33 lines · c
1// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s2// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s3// RUN: %clang_cc1 -verify -std=c11 -Wall -pedantic %s4// RUN: %clang_cc1 -verify -std=c99 -Wall -pedantic %s5 6/* WG14 N3505: Yes7 * Preprocessor integer expressions, v. 28 *9 * This introduces a constraint that preprocessing tokens must be an integer10 * literal, character literal, punctuator, or some other implementation-defined11 * sequence of tokens (to support builtins that insert odd tokens into the12 * parsing stream).13 */14 15// This is technically an integer constant expression, but it does not match16// 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#endif19 20// But with a character literal, it is fine.21#if 1 ? 1 : ('a' + 5) // Ok22#endif23 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#endif27 28// But some are.29#if 1 ? 1 : ~('a') // Ok30#endif31 32int x; // Needs a declaration to avoid a pedantic warning33