44 lines · c
1/* RUN: %clang_cc1 -fsyntax-only -std=c2y -pedantic -Wpre-c2y-compat -verify=compat %s2 RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -verify %s3 RUN: %clang_cc1 -fsyntax-only -std=c89 -pedantic -verify=expected,static-assert %s4 RUN: %clang_cc1 -fsyntax-only -pedantic -verify=cpp,static-assert -x c++ %s5 */6 7/* This tests the extension behavior for _Countof in language modes before C2y.8 * It also tests the behavior of the precompat warning. And it tests the9 * behavior in C++ mode where the extension is not supported.10 */11 12#if __STDC_VERSION__ < 202400L && !defined(__cplusplus)13#if __has_feature(c_countof)14#error "Did not expect _Countof to be a feature in older language modes"15#endif16 17#if !__has_extension(c_countof)18#error "Expected _Countof to be an extension in older language modes"19#endif20#endif /* __STDC_VERSION__ < 202400L && !defined(__cplusplus) */21 22#ifdef __cplusplus23/* C++ should not have this as a feature or as an extension. */24#if __has_feature(c_countof) || __has_extension(c_countof)25#error "did not expect there to be _Countof support"26#endif27#endif /* __cplusplus */28 29int array[12];30int x = _Countof(array); /* expected-warning {{'_Countof' is a C2y extension}}31 compat-warning {{'_Countof' is incompatible with C standards before C2y}}32 cpp-error {{use of undeclared identifier '_Countof'}}33 */34int y = _Countof(int[12]); /* expected-warning {{'_Countof' is a C2y extension}}35 compat-warning {{'_Countof' is incompatible with C standards before C2y}}36 cpp-error {{expected '(' for function-style cast or type construction}}37 */38 39_Static_assert(_Countof(int[12]) == 12, ""); /* expected-warning {{'_Countof' is a C2y extension}}40 compat-warning {{'_Countof' is incompatible with C standards before C2y}}41 cpp-error {{expected '(' for function-style cast or type construction}}42 static-assert-warning {{'_Static_assert' is a C11 extension}}43 */44