Author: Aaron Ballman Date: 2025-11-06T14:20:16-05:00 New Revision: b82c7e7819b3ef405838a82c6fda537d37a21dbf
URL: https://github.com/llvm/llvm-project/commit/b82c7e7819b3ef405838a82c6fda537d37a21dbf DIFF: https://github.com/llvm/llvm-project/commit/b82c7e7819b3ef405838a82c6fda537d37a21dbf.diff LOG: [C2y] Claim conformance to WG14 N3525 (#166824) The paper is ensuring that a static_assert operand can not be deferred until runtime; it must accept an integer constant expression which is resolved at compile time. Note, Clang extends what it considers to be a valid integer constant expression, so this also verifies the expected extension diagnostics. Added: clang/test/C/C2y/n3525.c Modified: clang/www/c_status.html Removed: ################################################################################ diff --git a/clang/test/C/C2y/n3525.c b/clang/test/C/C2y/n3525.c new file mode 100644 index 0000000000000..428df23c79ba2 --- /dev/null +++ b/clang/test/C/C2y/n3525.c @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s +// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s + +/* WG14 N3525: Yes + * static_assert without UB + * + * Ensures that a static_assert declaration cannot defer to runtime; it must + * take an integer constant expression that is resolved at compile time. + * + * Note: implementations are free to extend what is a valid integer constant + * expression, and Clang (and GCC) does so. So this test is validating that + * we quietly accept a pasing assertion, loudly reject a failing assertion, and + * issue a pedantic diagnostic for the extension case. + */ + +static_assert(1); // Okay + +static_assert(0); // expected-error {{static assertion failed}} + +extern int a; +static_assert(1 || a); // expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}} + +static_assert(a); // expected-error {{static assertion expression is not an integral constant expression}} +static_assert(0 || a); // expected-error {{static assertion expression is not an integral constant expression}} + +// Note, there is no CodeGen test for this; we have existing tests for the ICE +// extension, so the pedantic warning is sufficient to verify we're not +// emitting code which reads 'a' in '1 || a' because of the folding, and +// there's no way to generate code for reading 'a' in '0 || a' because of the +// error. diff --git a/clang/www/c_status.html b/clang/www/c_status.html index 80a52f791dfcf..2c1f6f4140a91 100644 --- a/clang/www/c_status.html +++ b/clang/www/c_status.html @@ -344,7 +344,7 @@ <h2 id="c2y">C2y implementation status</h2> <tr> <td>static_assert without UB</td> <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3525.htm">N3525</a></td> - <td class="unknown" align="center">Unknown</td> + <td class="full" align="center">Yes</td> </tr> <tr> <td>Allow calling static inline within extern inline</td> _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
