ucn-pp-identifier.c 3.6 KB

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