Home | History | Annotate | Download | only in Preprocessor
      1 // RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify -Wundef
      2 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify -Wundef
      3 // RUN: not %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -Wundef 2>&1 | FileCheck -strict-whitespace %s
      4 
      5 #define \u00FC
      6 #define a\u00FD() 0
      7 #ifndef \u00FC
      8 #error "This should never happen"
      9 #endif
     10 
     11 #if a\u00FD()
     12 #error "This should never happen"
     13 #endif
     14 
     15 #if a\U000000FD()
     16 #error "This should never happen"
     17 #endif
     18 
     19 #if \uarecool // expected-warning{{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{invalid token at start of a preprocessor expression}}
     20 #endif
     21 #if \uwerecool // expected-warning{{\u used with no following hex digits; treating as '\' followed by identifier}} expected-error {{invalid token at start of a preprocessor expression}}
     22 #endif
     23 #if \U0001000  // expected-warning{{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{invalid token at start of a preprocessor expression}}
     24 #endif
     25 
     26 // Make sure we reject disallowed UCNs
     27 #define \ufffe // expected-error {{macro name must be an identifier}}
     28 #define \U10000000  // expected-error {{macro name must be an identifier}}
     29 #define \u0061  // expected-error {{character 'a' cannot be specified by a universal character name}} expected-error {{macro name must be an identifier}}
     30 
     31 // FIXME: Not clear what our behavior should be here; \u0024 is "$".
     32 #define a\u0024  // expected-warning {{whitespace}}
     33 
     34 #if \u0110 // expected-warning {{is not defined, evaluates to 0}}
     35 #endif
     36 
     37 
     38 #define \u0110 1 / 0
     39 #if \u0110 // expected-error {{division by zero in preprocessor expression}}
     40 #endif
     41 
     42 #define STRINGIZE(X) # X
     43 
     44 extern int check_size[sizeof(STRINGIZE(\u0112)) == 3 ? 1 : -1];
     45 
     46 // Check that we still diagnose disallowed UCNs in #if 0 blocks.
     47 // C99 5.1.1.2p1 and C++11 [lex.phases]p1 dictate that preprocessor tokens are
     48 // formed before directives are parsed.
     49 // expected-error@+4 {{character 'a' cannot be specified by a universal character name}}
     50 #if 0
     51 #define \ufffe // okay
     52 #define \U10000000 // okay
     53 #define \u0061 // error, but -verify only looks at comments outside #if 0
     54 #endif
     55 
     56 
     57 // A UCN formed by token pasting is undefined in both C99 and C++.
     58 // Right now we don't do anything special, which causes us to coincidentally
     59 // accept the first case below but reject the second two.
     60 #define PASTE(A, B) A ## B
     61 extern int PASTE(\, u00FD);
     62 extern int PASTE(\u, 00FD); // expected-warning{{\u used with no following hex digits}}
     63 extern int PASTE(\u0, 0FD); // expected-warning{{incomplete universal character name}}
     64 #ifdef __cplusplus
     65 // expected-error@-3 {{expected unqualified-id}}
     66 // expected-error@-3 {{expected unqualified-id}}
     67 #else
     68 // expected-error@-6 {{expected identifier}}
     69 // expected-error@-6 {{expected identifier}}
     70 #endif
     71 
     72 
     73 // A UCN produced by line splicing is valid in C99 but undefined in C++.
     74 // Since undefined behavior can do anything including working as intended,
     75 // we just accept it in C++ as well.;
     76 #define newline_1_\u00F\
     77 C 1
     78 #define newline_2_\u00\
     79 F\
     80 C 1
     81 #define newline_3_\u\
     82 00\
     83 FC 1
     84 #define newline_4_\\
     85 u00FC 1
     86 #define newline_5_\\
     87 u\
     88 \
     89 0\
     90 0\
     91 F\
     92 C 1
     93 
     94 #if (newline_1_\u00FC && newline_2_\u00FC && newline_3_\u00FC && \
     95      newline_4_\u00FC && newline_5_\u00FC)
     96 #else
     97 #error "Line splicing failed to produce UCNs"
     98 #endif
     99 
    100 
    101 #define capital_u_\U00FC
    102 // expected-warning@-1 {{incomplete universal character name}} expected-note@-1 {{did you mean to use '\u'?}} expected-warning@-1 {{whitespace}}
    103 // CHECK: note: did you mean to use '\u'?
    104 // CHECK-NEXT:   #define capital_u_\U00FC
    105 // CHECK-NEXT: {{^                   \^}}
    106 // CHECK-NEXT: {{^                   u}}
    107