* gcc.dg/cpp/lexstrng.c: Don't include string.h.
[official-gcc.git] / gcc / testsuite / gcc.dg / cpp / lexstrng.c
blobb0353300395f3ae39b33924f3cdf2427bfad1d63
1 /* Copyright (C) 2000 Free Software Foundation, Inc. */
3 /* { dg-do run } */
4 /* { dg-options "-trigraphs" } */
6 /* Test lexing of strings and character constants. */
8 #ifndef __WCHAR_TYPE__
9 #define __WCHAR_TYPE__ int
10 #endif
11 typedef __WCHAR_TYPE__ wchar_t;
13 extern int strcmp (const char *, const char *);
14 extern int puts (const char *);
15 extern void abort (void);
16 #define err(str) do { puts(str); abort(); } while (0)
18 /* Escaped newlines. */
19 const char *str1 = "s\
22 r??/
23 1";
25 const char x = '\
26 ??/
27 b';
29 /* Test escaped terminators. */
30 const char *term = "\"\\\"\\";
31 const char termc = '\'';
32 const char *terms = "'";
34 /* Test wide strings and chars are lexed. */
35 const wchar_t wchar = L'w';
36 const wchar_t* wstring = L"wide string";
38 /* Test all 9 trigraphs embedded in a string. Test trigraphs do not
39 survive an embedded backslash newline. Test trigraphs preceded by
40 a '?' are still noticed. */
41 const char *t = "??/\??<??>??=??)??\
42 (??(??!??'??-???=???/
43 ?-";
45 int main (int argc, char *argv[])
47 if (strcmp (str1, "str 1"))
48 err ("str1");
50 if (x != 'b')
51 err ("b");
53 /* We have to split the string up to avoid trigraph replacement
54 here. Split the 2 trigraphs after both 1 and 2 ?s; just doing
55 this exposed a bug in the initial release of the tokenized lexer. */
56 if (strcmp (t, "\\{}#]?" "?([|^~?#??" "-"))
57 err ("Embedded trigraphs");
59 if (term[0] != '"' || term[1] != '\\' || term[2] != '"'
60 || term[3] != '\\' || term[4] != '\0')
61 err ("Escaped string terminators");
63 if (termc != terms[0])
64 err ("Escaped character constant terminator");
66 return 0;