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