1 /* Copyright (C) 2000 Free Software Foundation, Inc.  */
2 
3 /* { dg-do run } */
4 /* { dg-options "-trigraphs" } */
5 
6 /* Test lexing of strings and character constants.  */
7 
8 #ifndef __WCHAR_TYPE__
9 #define __WCHAR_TYPE__ int
10 #endif
11 typedef __WCHAR_TYPE__ wchar_t;
12 
13 extern int strcmp (const char *, const char *);
14 #if DEBUG
15 extern int puts (const char *);
16 #else
17 #define puts(X)
18 #endif
19 extern void abort (void);
20 #define err(str) do { puts(str); abort(); } while (0)
21 
22 /* Escaped newlines.  */
23 const char *str1 = "s\
24 t\
25 \
26 r??/
27   1";
28 
29 const char x = '\
30 ??/
31 b';
32 
33 /* Test escaped terminators.  */
34 const char *term = "\"\\\"\\";
35 const char termc = '\'';
36 const char *terms = "'";
37 
38 /* Test wide strings and chars are lexed.  */
39 const wchar_t wchar = L'w';
40 const wchar_t* wstring = L"wide string";
41 
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 = "??/\??<??>??=??)??\
46 (??(??!??'??-???=???/
47 ?-";
48 
main(int argc,char * argv[])49 int main (int argc, char *argv[])
50 {
51   if (strcmp (str1, "str  1"))
52     err ("str1");
53 
54   if (x != 'b')
55     err ("b");
56 
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");
62 
63   if (term[0] != '"' || term[1] != '\\' || term[2] != '"'
64       || term[3] != '\\' || term[4] != '\0')
65     err ("Escaped string terminators");
66 
67   if (termc != terms[0])
68     err ("Escaped character constant terminator");
69 
70   return 0;
71 }
72