[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Preprocessor / macro_vaopt_expand.cpp
blob5eb0facb83f7364f2e068e236c70d58dfba6e435
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
5 #define LPAREN (
6 #define RPAREN )
8 #define A0 expandedA0
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 )
18 #define F(x, y) x + y
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);
23 #undef F
24 #undef ELLIP_FUNC
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)
34 // CHECK: 4: f(0 )
35 #undef F
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)
42 7.1: G(a,,)
45 // CHECK: 5: f(0, a , b, c)
46 // CHECK: 6: f(0, a )
47 // CHECK: 7: f(0, a )
48 // CHECK: 7.1: f(0, a , ,)
49 #undef G
51 #define HT_B() TONG
53 #define F(x, ...) HT_ ## __VA_OPT__(x x A() #x)
55 8: F(1)
56 9: F(A(),1)
58 // CHECK: 8: HT_
59 // CHECK: 9: TONG C ( ) B ( ) "A()"
60 #undef HT_B
61 #undef F
63 #define F(a,...) #__VA_OPT__(A1 a)
65 10: F(A())
66 11: F(A1 A(), 1)
67 // CHECK: 10: ""
68 // CHECK: 11: "A1 expandedA1 expandedA0 B ( )"
69 #undef F
72 #define F(a,...) a ## __VA_OPT__(A1 a) ## __VA_ARGS__ ## a
73 12.0: F()
74 12: F(,)
75 13: F(B,)
76 // CHECK: 12.0:
77 // CHECK: 12:
78 // CHECK: 13: BB
79 #undef F
81 #define F(...) #__VA_OPT__() X ## __VA_OPT__() #__VA_OPT__( )
83 14: F()
84 15: F(1)
86 // CHECK: 14: "" X ""
87 // CHECK: 15: "" X ""
89 #undef F
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 };
96 // CHECK: 16: S foo ;
97 // CHECK: 17: S bar = { 1, 2 };
98 #undef SDEF
100 #define F(a,...) A() #__VA_OPT__(A3 __VA_ARGS__ a ## __VA_ARGS__ ## a ## C A3) A()
102 18: F()
103 19: F(,)
104 20: F(,A3)
105 21: F(A3, A(),A0)
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 ( )
113 #undef F
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()
117 22: F()
118 23: F(,)
119 24: F(,A0)
120 25: F(A0, A(),A0)
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 ( )
128 #undef F
130 #define F(a,...) __VA_OPT__(B a ## a) ## 1
131 #define G(a,...) __VA_OPT__(B a) ## 1
132 26: F(,1)
133 26_1: G(,1)
134 // CHECK: 26: B 1
135 // CHECK: 26_1: B 1
136 #undef F
137 #undef G
139 #define F(a,...) B ## __VA_OPT__(a 1) ## 1
140 #define G(a,...) B ## __VA_OPT__(a ## a 1) ## 1
142 27: F(,1)
143 27_1: F(A0,1)
144 28: G(,1)
145 // CHECK: 27: B 11
146 // CHECK: 27_1: BexpandedA0 11
147 // CHECK: 28: B 11
149 #undef F
150 #undef G