1 // RUN: %clang_cc1 -E %s -pedantic -std=c++2a | FileCheck -strict-whitespace %s 2 3 #define LPAREN ( 4 #define RPAREN ) 5 6 #define A0 expandedA0 7 #define A1 expandedA1 A0 8 #define A2 expandedA2 A1 9 #define A3 expandedA3 A2 10 11 #define A() B LPAREN ) 12 #define B() C LPAREN ) 13 #define C() D LPAREN ) 14 15 16 #define F(x, y) x + y 17 #define ELLIP_FUNC(...) __VA_OPT__(__VA_ARGS__) 18 19 1: ELLIP_FUNC(F, LPAREN, 'a', 'b', RPAREN); 20 2: ELLIP_FUNC(F LPAREN 'a', 'b' RPAREN); 21 #undef F 22 #undef ELLIP_FUNC 23 24 // CHECK: 1: F, (, 'a', 'b', ); 25 // CHECK: 2: 'a' + 'b'; 26 27 #define F(...) f(0 __VA_OPT__(,) __VA_ARGS__) 28 3: F(a, b, c) // replaced by f(0, a, b, c) 29 4: F() // replaced by f(0) 30 31 // CHECK: 3: f(0 , a, b, c) 32 // CHECK: 4: f(0 ) 33 #undef F 34 35 #define G(X, ...) f(0, X __VA_OPT__(,) __VA_ARGS__) 36 37 5: G(a, b, c) // replaced by f(0, a , b, c) 38 6: G(a) // replaced by f(0, a) 39 7: G(a,) // replaced by f(0, a) 40 7.1: G(a,,) 41 42 43 // CHECK: 5: f(0, a , b, c) 44 // CHECK: 6: f(0, a ) 45 // CHECK: 7: f(0, a ) 46 // CHECK: 7.1: f(0, a , ,) 47 #undef G 48 49 #define HT_B() TONG 50 51 #define F(x, ...) HT_ ## __VA_OPT__(x x A() #x) 52 53 8: F(1) 54 9: F(A(),1) 55 56 // CHECK: 8: HT_ 57 // CHECK: 9: TONG C ( ) B ( ) "A()" 58 #undef HT_B 59 #undef F 60 61 #define F(a,...) #__VA_OPT__(A1 a) 62 63 10: F(A()) 64 11: F(A1 A(), 1) 65 // CHECK: 10: "" 66 // CHECK: 11: "A1 expandedA1 expandedA0 B ( )" 67 #undef F 68 69 70 #define F(a,...) a ## __VA_OPT__(A1 a) ## __VA_ARGS__ ## a 71 12.0: F() 72 12: F(,) 73 13: F(B,) 74 // CHECK: 12.0: 75 // CHECK: 12: 76 // CHECK: 13: BB 77 #undef F 78 79 #define F(...) #__VA_OPT__() X ## __VA_OPT__() #__VA_OPT__( ) 80 81 14: F() 82 15: F(1) 83 84 // CHECK: 14: "" X "" 85 // CHECK: 15: "" X "" 86 87 #undef F 88 89 #define SDEF(sname, ...) S sname __VA_OPT__(= { __VA_ARGS__ }) 90 91 16: SDEF(foo); // replaced by S foo; 92 17: SDEF(bar, 1, 2); // replaced by S bar = { 1, 2 }; 93 94 // CHECK: 16: S foo ; 95 // CHECK: 17: S bar = { 1, 2 }; 96 #undef SDEF 97 98 #define F(a,...) A() #__VA_OPT__(A3 __VA_ARGS__ a ## __VA_ARGS__ ## a ## C A3) A() 99 100 18: F() 101 19: F(,) 102 20: F(,A3) 103 21: F(A3, A(),A0) 104 105 106 // CHECK: 18: B ( ) "" B ( ) 107 // CHECK: 19: B ( ) "" B ( ) 108 // CHECK: 20: B ( ) "A3 expandedA3 expandedA2 expandedA1 expandedA0 A3C A3" B ( ) 109 // CHECK: 21: B ( ) "A3 B ( ),expandedA0 A3A(),A0A3C A3" B ( ) 110 111 #undef F 112 113 #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() 114 115 22: F() 116 23: F(,) 117 24: F(,A0) 118 25: F(A0, A(),A0) 119 120 121 // CHECK: 22: B ( ) "" B ( ) 122 // CHECK: 23: B ( ) "" B ( ) 123 // CHECK: 24: B ( ) "A3 expandedA0 A0C A3" expandedA0 expandedA0 A0C expandedA0 B ( ) 124 // CHECK: 25: B ( ) "A3 B ( ),expandedA0 A0A(),A0A0C A3" expandedA0 expandedA0 C ( ),expandedA0 A0A(),A0A0C expandedA0 B ( ) 125 126 #undef F 127 128 #define F(a,...) __VA_OPT__(B a ## a) ## 1 129 #define G(a,...) __VA_OPT__(B a) ## 1 130 26: F(,1) 131 26_1: G(,1) 132 // CHECK: 26: B 1 133 // CHECK: 26_1: B 1 134 #undef F 135 #undef G 136 137 #define F(a,...) B ## __VA_OPT__(a 1) ## 1 138 #define G(a,...) B ## __VA_OPT__(a ## a 1) ## 1 139 140 27: F(,1) 141 27_1: F(A0,1) 142 28: G(,1) 143 // CHECK: 27: B 11 144 // CHECK: 27_1: BexpandedA0 11 145 // CHECK: 28: B 11 146 147 #undef F 148 #undef G 149