1 // RUN: %clang_cc1 -E %s -pedantic -std=c++20 | FileCheck -strict-whitespace %s
2 // RUN: %clang_cc1 -E %s -pedantic -std=c++11 | FileCheck -strict-whitespace %s
3 // RUN: %clang_cc1 -E -x c %s -pedantic -std=c99 | FileCheck -strict-whitespace %s
9 #define A1 expandedA1 A0
10 #define A2 expandedA2 A1
11 #define A3 expandedA3 A2
13 #define A() B LPAREN )
14 #define B() C LPAREN )
15 #define C() D LPAREN )
19 #define ELLIP_FUNC(...) __VA_OPT__(__VA_ARGS__)
21 1: ELLIP_FUNC(F
, LPAREN
, 'a', 'b', RPAREN
);
22 2: ELLIP_FUNC(F LPAREN
'a', 'b' RPAREN
);
26 // CHECK: 1: F, (, 'a', 'b', );
27 // CHECK: 2: 'a' + 'b';
29 #define F(...) f(0 __VA_OPT__(,) __VA_ARGS__)
30 3: F(a
, b
, c
) // replaced by f(0, a, b, c)
31 4: F() // replaced by f(0)
33 // CHECK: 3: f(0 , a, b, c)
37 #define G(X, ...) f(0, X __VA_OPT__(,) __VA_ARGS__)
39 5: G(a
, b
, c
) // replaced by f(0, a , b, c)
40 6: G(a
) // replaced by f(0, a)
41 7: G(a
,) // replaced by f(0, a)
45 // CHECK: 5: f(0, a , b, c)
48 // CHECK: 7.1: f(0, a , ,)
53 #define F(x, ...) HT_ ## __VA_OPT__(x x A() #x)
59 // CHECK: 9: TONG C ( ) B ( ) "A()"
63 #define F(a,...) #__VA_OPT__(A1 a)
68 // CHECK: 11: "A1 expandedA1 expandedA0 B ( )"
72 #define F(a,...) a ## __VA_OPT__(A1 a) ## __VA_ARGS__ ## a
81 #define F(...) #__VA_OPT__() X ## __VA_OPT__() #__VA_OPT__( )
91 #define SDEF(sname, ...) S sname __VA_OPT__(= { __VA_ARGS__ })
93 16: SDEF(foo
); // replaced by S foo;
94 17: SDEF(bar
, 1, 2); // replaced by S bar = { 1, 2 };
97 // CHECK: 17: S bar = { 1, 2 };
100 #define F(a,...) A() #__VA_OPT__(A3 __VA_ARGS__ a ## __VA_ARGS__ ## a ## C A3) A()
108 // CHECK: 18: B ( ) "" B ( )
109 // CHECK: 19: B ( ) "" B ( )
110 // CHECK: 20: B ( ) "A3 expandedA3 expandedA2 expandedA1 expandedA0 A3C A3" B ( )
111 // CHECK: 21: B ( ) "A3 B ( ),expandedA0 A3A(),A0A3C A3" B ( )
115 #define F(a,...) A() #__VA_OPT__(A3 __VA_ARGS__ a ## __VA_ARGS__ ## a ## C A3) a __VA_OPT__(A0 __VA_ARGS__ a ## __VA_ARGS__ ## a ## C A0) A()
123 // CHECK: 22: B ( ) "" B ( )
124 // CHECK: 23: B ( ) "" B ( )
125 // CHECK: 24: B ( ) "A3 expandedA0 A0C A3" expandedA0 expandedA0 A0C expandedA0 B ( )
126 // CHECK: 25: B ( ) "A3 B ( ),expandedA0 A0A(),A0A0C A3" expandedA0 expandedA0 C ( ),expandedA0 A0A(),A0A0C expandedA0 B ( )
130 #define F(a,...) __VA_OPT__(B a ## a) ## 1
131 #define G(a,...) __VA_OPT__(B a) ## 1
139 #define F(a,...) B ## __VA_OPT__(a 1) ## 1
140 #define G(a,...) B ## __VA_OPT__(a ## a 1) ## 1
146 // CHECK: 27_1: BexpandedA0 11