|
| 1 | +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++98 |
| 2 | +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++11 |
| 3 | +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++14 |
| 4 | +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++17 |
| 5 | +// RUN: %clang_cc1 -E -pedantic-errors %s -verify -std=c++20 |
| 6 | +// RUN: %clang_cc1 -E -pedantic-errors %s -verify=expected,since-cxx23 -std=c++23 -Wno-c23-extensions |
| 7 | +// RUN: %clang_cc1 -E -pedantic-errors %s -verify=expected,since-cxx23 -std=c++2c -Wno-c23-extensions |
| 8 | + |
| 9 | +// Test 1: Top-level comma |
| 10 | +// expected-error@+1 {{expected end of line in preprocessor expression}} |
| 11 | +#if 1, 2 |
| 12 | +#endif |
| 13 | + |
| 14 | +// Test 2: Comma in conditional expression(CWG3017) |
| 15 | +// Per CWG 3017, this exact case highlights the specification gap |
| 16 | +// where C++ lacks explicit prohibition of comma operators in #if |
| 17 | +// expected-error@+1 {{comma operator in operand of #if}} |
| 18 | +#if 1 ? 1, 0 : 3 |
| 19 | +#endif |
| 20 | + |
| 21 | +// Test 3: Parenthesized comma |
| 22 | +// expected-error@+1 {{comma operator in operand of #if}} |
| 23 | +#if (1, 2) |
| 24 | +#endif |
| 25 | + |
| 26 | +// Test 4: Multiple commas |
| 27 | +// expected-error@+1 {{expected end of line in preprocessor expression}} |
| 28 | +#if 1, 2, 3 |
| 29 | +#endif |
| 30 | + |
| 31 | +// Test 5: Comma in #elif |
| 32 | +#if 0 |
| 33 | +#elif (1, 2) // expected-error {{comma operator in operand of #if}} |
| 34 | +#endif |
| 35 | + |
| 36 | +// Test 6: Leading comma (syntax error) |
| 37 | +// expected-error@+1 {{invalid token at start of a preprocessor expression}} |
| 38 | +#if , |
| 39 | +#endif |
| 40 | + |
| 41 | +// Test 7: Comma in #embed limit parameter (C++23+) |
| 42 | +#if __cplusplus >= 202302L |
| 43 | +// since-cxx23-error@+1 {{expected ')'}} |
| 44 | +#embed "jk.txt" limit(1, 2) |
| 45 | +#endif |
0 commit comments