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 
8 // GCC PR 20077
9 
10 #define a   a ## ## // expected-error {{'##' cannot appear at end of macro expansion}}
11 #define b() b ## ## // expected-error {{'##' cannot appear at end of macro expansion}}
12 #define c   c ##    // expected-error {{'##' cannot appear at end of macro expansion}}
13 #define d() d ##    // expected-error {{'##' cannot appear at end of macro expansion}}
14 
15 
16 #define e   ## ## e // expected-error {{'##' cannot appear at start of macro expansion}}
17 #define f() ## ## f // expected-error {{'##' cannot appear at start of macro expansion}}
18 #define g   ## g    // expected-error {{'##' cannot appear at start of macro expansion}}
19 #define h() ## h    // expected-error {{'##' cannot appear at start of macro expansion}}
20 #define i   ##      // expected-error {{'##' cannot appear at start of macro expansion}}
21 #define j() ##      // expected-error {{'##' cannot appear at start of macro expansion}}
22 
23 // Invalid token pasting.
24 // PR3918
25 
26 // When pasting creates poisoned identifiers, we error.
27 #pragma GCC poison BLARG
28 BLARG  // expected-error {{attempt to use a poisoned identifier}}
29 #define XX BL ## ARG
30 XX     // expected-error {{attempt to use a poisoned identifier}}
31 
32 #define VA __VA_ ## ARGS__
33 int VA;   // expected-warning {{__VA_ARGS__ can only appear in the expansion of a C99 variadic macro}}
34 
35 #define LOG_ON_ERROR(x) x ## #y; // expected-error {{'#' is not followed by a macro parameter}}
36 LOG_ON_ERROR(0);
37 
38 #define PR21379A(x) printf ##x // expected-note {{macro 'PR21379A' defined here}}
39 PR21379A(0 {, }) // expected-error {{too many arguments provided to function-like macro invocation}}
40                  // expected-note@-1 {{parentheses are required around macro argument containing braced initializer list}}
41 
42 #define PR21379B(x) printf #x // expected-note {{macro 'PR21379B' defined here}}
43 PR21379B(0 {, }) // expected-error {{too many arguments provided to function-like macro invocation}}
44                  // expected-note@-1 {{parentheses are required around macro argument containing braced initializer list}}
45