1 /* Copyright (C) 2000 Free Software Foundation, Inc. */
4 /* { dg-options "-trigraphs" } */
6 /* Test lexing of strings and character constants. */
10 #ifndef __WCHAR_TYPE__
11 #define __WCHAR_TYPE__ int
13 typedef __WCHAR_TYPE__ wchar_t;
15 extern int strcmp (const char *, const char *);
16 extern int puts (const char *);
17 extern void abort (void);
18 #define err(str) do { puts(str); abort(); } while (0)
20 /* Escaped newlines. */
21 const char *str1 = "s\
31 /* Test escaped terminators. */
32 const char *term = "\"\\\"\\";
33 const char termc = '\'';
34 const char *terms = "'";
36 /* Test wide strings and chars are lexed. */
37 const wchar_t wchar = L'w';
38 const wchar_t* wstring = L"wide string";
40 /* Test all 9 trigraphs embedded in a string. Test trigraphs do not
41 survive an embedded backslash newline. Test trigraphs preceded by
42 a '?' are still noticed. */
43 const char *t = "??/\??<??>??=??)??\
47 int main (int argc, char *argv[])
49 if (strcmp (str1, "str 1"))
55 /* We have to split the string up to avoid trigraph replacement
56 here. Split the 2 trigraphs after both 1 and 2 ?s; just doing
57 this exposed a bug in the initial release of the tokenized lexer. */
58 if (strcmp (t, "\\{}#]?" "?([|^~?#??" "-"))
59 err ("Embedded trigraphs");
61 if (term[0] != '"' || term[1] != '\\' || term[2] != '"'
62 || term[3] != '\\' || term[4] != '\0')
63 err ("Escaped string terminators");
65 if (termc != terms[0])
66 err ("Escaped character constant terminator");