| 1 |
// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s |
| 2 |
// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s |
| 3 |
// RUN: %clang_cc1 -verify -std=c11 -Wall -pedantic %s |
| 4 |
// RUN: %clang_cc1 -verify -std=c99 -Wall -pedantic %s |
| 5 |
|
| 6 |
/* WG14 N3505: Yes |
| 7 |
* Preprocessor integer expressions, v. 2 |
| 8 |
* |
| 9 |
* This introduces a constraint that preprocessing tokens must be an integer |
| 10 |
* literal, character literal, punctuator, or some other implementation-defined |
| 11 |
* sequence of tokens (to support builtins that insert odd tokens into the |
| 12 |
* parsing stream). |
| 13 |
*/ |
| 14 |
|
| 15 |
// This is technically an integer constant expression, but it does not match |
| 16 |
// the new constraints and thus needs to be diagnosed. |
| 17 |
#if 1 ? 1 : (""[0] += 5) // expected-error {{invalid token at start of a preprocessor expression}} |
| 18 |
#endif |
| 19 |
|
| 20 |
// But with a character literal, it is fine. |
| 21 |
#if 1 ? 1 : ('a' + 5) // Ok |
| 22 |
#endif |
| 23 |
|
| 24 |
// This doesn't mean that all punctuators are fine, however. |
| 25 |
#if 1 ? 1 : ('a' += 5) // expected-error {{token is not a valid binary operator in a preprocessor subexpression}} |
| 26 |
#endif |
| 27 |
|
| 28 |
// But some are. |
| 29 |
#if 1 ? 1 : ~('a') // Ok |
| 30 |
#endif |
| 31 |
|
| 32 |
int x; // Needs a declaration to avoid a pedantic warning |