macro_paste_bad.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // RUN: %clang_cc1 -Eonly -verify -pedantic %s
  2. // pasting ""x"" and ""+"" does not give a valid preprocessing token
  3. #define XYZ x ## +
  4. XYZ // expected-error {{pasting formed 'x+', an invalid preprocessing token}}
  5. #define XXYZ . ## test
  6. XXYZ // expected-error {{pasting formed '.test', an invalid preprocessing token}}
  7. // GCC PR 20077
  8. #define a a ## ## // expected-error {{'##' cannot appear at end of macro expansion}}
  9. #define b() b ## ## // expected-error {{'##' cannot appear at end of macro expansion}}
  10. #define c c ## // expected-error {{'##' cannot appear at end of macro expansion}}
  11. #define d() d ## // expected-error {{'##' cannot appear at end of macro expansion}}
  12. #define e ## ## e // expected-error {{'##' cannot appear at start of macro expansion}}
  13. #define f() ## ## f // expected-error {{'##' cannot appear at start of macro expansion}}
  14. #define g ## g // expected-error {{'##' cannot appear at start of macro expansion}}
  15. #define h() ## h // expected-error {{'##' cannot appear at start of macro expansion}}
  16. #define i ## // expected-error {{'##' cannot appear at start of macro expansion}}
  17. #define j() ## // expected-error {{'##' cannot appear at start of macro expansion}}
  18. // Invalid token pasting.
  19. // PR3918
  20. // When pasting creates poisoned identifiers, we error.
  21. #pragma GCC poison BLARG
  22. BLARG // expected-error {{attempt to use a poisoned identifier}}
  23. #define XX BL ## ARG
  24. XX // expected-error {{attempt to use a poisoned identifier}}
  25. #define VA __VA_ ## ARGS__
  26. int VA; // expected-warning {{__VA_ARGS__ can only appear in the expansion of a C99 variadic macro}}
  27. #define LOG_ON_ERROR(x) x ## #y; // expected-error {{'#' is not followed by a macro parameter}}
  28. LOG_ON_ERROR(0);
  29. #define PR21379A(x) printf ##x // expected-note {{macro 'PR21379A' defined here}}
  30. PR21379A(0 {, }) // expected-error {{too many arguments provided to function-like macro invocation}}
  31. // expected-note@-1 {{parentheses are required around macro argument containing braced initializer list}}
  32. #define PR21379B(x) printf #x // expected-note {{macro 'PR21379B' defined here}}
  33. PR21379B(0 {, }) // expected-error {{too many arguments provided to function-like macro invocation}}
  34. // expected-note@-1 {{parentheses are required around macro argument containing braced initializer list}}