| 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. |