Files
TheRock/compiler/amd-llvm/clang/test/C/C11/n1330.c
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

75 lines
3.4 KiB
C

// RUN: %clang_cc1 -verify -Wgnu-folding-constant %s
/* WG14 N1330: Yes
* Static assertions
*/
// Test syntactic requirements: first argument must be a constant expression,
// and the second argument must be a string literal. We support the C2x
// extension that allows you to elide the second argument.
int a;
_Static_assert(a, ""); // expected-error {{static assertion expression is not an integral constant expression}}
_Static_assert(1); // expected-warning {{'_Static_assert' with no message is a C23 extension}}
// Test functional requirements
_Static_assert(1, "this works");
_Static_assert(0, "this fails"); // expected-error {{static assertion failed: this fails}}
_Static_assert(0); // expected-error {{static assertion failed}} \
expected-warning {{'_Static_assert' with no message is a C23 extension}}
// Test declaration contexts. We've already demonstrated that file scope works.
struct S {
_Static_assert(1, "this works");
union U {
long l;
_Static_assert(1, "this works");
} u;
enum E {
_Static_assert(1, "this should not compile"); // expected-error {{expected identifier}}
One
} e;
};
void func( // expected-note {{to match this '('}}
_Static_assert(1, "this should not compile") // expected-error {{expected parameter declarator}} \
expected-error {{expected ')'}}
);
void func( // expected-note {{to match this '('}}
_Static_assert(1, "this should not compile") // expected-error {{expected parameter declarator}} \
expected-error {{expected ')'}}
) {}
void test(void) {
_Static_assert(1, "this works");
_Static_assert(0, "this fails"); // expected-error {{static assertion failed: this fails}}
// While the use of a _Static_assert in a for loop declaration is prohibited per
// 6.8.5p3 (requiring the declaration to only declare identifiers for objects
// having auto or register storage class; a static assertion does not declare
// an identifier nor an object), we permit it as an extension.
int i = 0;
for (_Static_assert(1, "this should compile"); i < 10; ++i)
;
// Ensure that only an integer constant expression can be used as the
// controlling expression.
_Static_assert(1.0f, "this should not compile"); // expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
}
#if __STDC_VERSION__ < 202311L
// The use of a _Static_assert in a K&R C function definition is prohibited per
// 6.9.1p6 requiring each declaration to have a declarator (which a static
// assertion does not have) and only declare identifiers from the identifier
// list.
// The error about expecting a ';' is due to the static assertion confusing the
// compiler. It'd be nice if we improved the diagnostics here, but because this
// involves a K&R C declaration, it's low priority.
void knr(a, b, c) // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C23}}
int a, b; // expected-error {{expected ';' at end of declaration}}
_Static_assert(1, "this should not compile"); // expected-error {{expected identifier or '('}} \
expected-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
float c;
{
}
#endif // __STDC_VERSION__