Author: Aaron Ballman Date: 2025-03-11T15:04:11-04:00 New Revision: 456fa47bab479f0ef1136d07687bd1b2635b1a26
URL: https://github.com/llvm/llvm-project/commit/456fa47bab479f0ef1136d07687bd1b2635b1a26 DIFF: https://github.com/llvm/llvm-project/commit/456fa47bab479f0ef1136d07687bd1b2635b1a26.diff LOG: [C2y] Claim conformance to WG14 N3505 This paper clarified that conditional inclusion in the preprocessor requires the integer constant expression to be comprised only of integer and character literals, punctuators, or implementation-defined tokens. This is something Clang has always required. Added: clang/test/C/C2y/n3505.c Modified: clang/www/c_status.html Removed: ################################################################################ diff --git a/clang/test/C/C2y/n3505.c b/clang/test/C/C2y/n3505.c new file mode 100644 index 0000000000000..7f307390e09ca --- /dev/null +++ b/clang/test/C/C2y/n3505.c @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s +// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s +// RUN: %clang_cc1 -verify -std=c11 -Wall -pedantic %s +// RUN: %clang_cc1 -verify -std=c99 -Wall -pedantic %s + +/* WG14 N3505: Yes + * Preprocessor integer expressions, v. 2 + * + * This introduces a constraint that preprocessing tokens must be an integer + * literal, character literal, punctuator, or some other implementation-defined + * sequence of tokens (to support builtins that insert odd tokens into the + * parsing stream). + */ + +// This is technically an integer constant expression, but it does not match +// the new constraints and thus needs to be diagnosed. +#if 1 ? 1 : (""[0] += 5) // expected-error {{invalid token at start of a preprocessor expression}} +#endif + +// But with a character literal, it is fine. +#if 1 ? 1 : ('a' + 5) // Ok +#endif + +// This doesn't mean that all punctuators are fine, however. +#if 1 ? 1 : ('a' += 5) // expected-error {{token is not a valid binary operator in a preprocessor subexpression}} +#endif + +// But some are. +#if 1 ? 1 : ~('a') // Ok +#endif + +int x; // Needs a declaration to avoid a pedantic warning diff --git a/clang/www/c_status.html b/clang/www/c_status.html index af3415e663e9d..4432e62b47520 100644 --- a/clang/www/c_status.html +++ b/clang/www/c_status.html @@ -268,7 +268,7 @@ <h2 id="c2y">C2y implementation status</h2> <tr> <td>Preprocessor integer expressions, v. 2</td> <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3505.pdf">N3505</a></td> - <td class="unknown" align="center">Unknown</td> + <td class="full" align="center">Yes</td> </tr> <tr> <td>Initialization of anonymous structures and unions</td> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits