31 lines · c
1// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s2// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s3 4/* WG14 N3525: Yes5 * static_assert without UB6 *7 * Ensures that a static_assert declaration cannot defer to runtime; it must8 * take an integer constant expression that is resolved at compile time.9 *10 * Note: implementations are free to extend what is a valid integer constant11 * expression, and Clang (and GCC) does so. So this test is validating that12 * we quietly accept a pasing assertion, loudly reject a failing assertion, and13 * issue a pedantic diagnostic for the extension case.14 */15 16static_assert(1); // Okay17 18static_assert(0); // expected-error {{static assertion failed}}19 20extern int a;21static_assert(1 || a); // expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}22 23static_assert(a); // expected-error {{static assertion expression is not an integral constant expression}}24static_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 ICE27// extension, so the pedantic warning is sufficient to verify we're not28// emitting code which reads 'a' in '1 || a' because of the folding, and29// there's no way to generate code for reading 'a' in '0 || a' because of the30// error.31