File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1+ // RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s
2+ // RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s
3+
4+ /* WG14 N3525: Yes
5+ * static_assert without UB
6+ *
7+ * Ensures that a static_assert declaration cannot defer to runtime; it must
8+ * take an integer constant expression that is resolved at compile time.
9+ *
10+ * Note: implementations are free to extend what is a valid integer constant
11+ * expression, and Clang (and GCC) does so. So this test is validating that
12+ * we quietly accept a pasing assertion, loudly reject a failing assertion, and
13+ * issue a pedantic diagnostic for the extension case.
14+ */
15+
16+ static_assert (1 ); // Okay
17+
18+ static_assert (0 ); // expected-error {{static assertion failed}}
19+
20+ extern int a ;
21+ static_assert (1 || a ); // expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
22+
23+ static_assert (a ); // expected-error {{static assertion expression is not an integral constant expression}}
24+ static_assert (0 || a ); // expected-error {{static assertion expression is not an integral constant expression}}
25+
26+ // Note, there is no CodeGen test for this; we have existing tests for the ICE
27+ // extension, so the pedantic warning is sufficient to verify we're not
28+ // emitting code which reads 'a' in '1 || a' because of the folding, and
29+ // there's no way to generate code for reading 'a' in '0 || a' because of the
30+ // error.
Original file line number Diff line number Diff line change @@ -344,7 +344,7 @@ <h2 id="c2y">C2y implementation status</h2>
344344 < tr >
345345 < td > static_assert without UB</ td >
346346 < td > < a href ="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3525.htm "> N3525</ a > </ td >
347- < td class ="unknown " align ="center "> Unknown </ td >
347+ < td class ="full " align ="center "> Yes </ td >
348348 </ tr >
349349 < tr >
350350 < td > Allow calling static inline within extern inline</ td >
You can’t perform that action at this time.
0 commit comments