Debian Codegraph @

clang/test/C/C2y/n3369_1.c

raw
1 /* RUN: %clang_cc1 -fsyntax-only -std=c2y -pedantic -Wpre-c2y-compat -verify=compat %s
2 RUN: %clang_cc1 -fsyntax-only -std=c23 -pedantic -verify %s
3 RUN: %clang_cc1 -fsyntax-only -std=c89 -pedantic -verify=expected,static-assert %s
4 RUN: %clang_cc1 -fsyntax-only -pedantic -verify=cpp,static-assert -x c++ %s
5 */
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 the
9 * 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 #endif
16
17 #if !__has_extension(c_countof)
18 #error "Expected _Countof to be an extension in older language modes"
19 #endif
20 #endif /* __STDC_VERSION__ < 202400L && !defined(__cplusplus) */
21
22 #ifdef __cplusplus
23 /* 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 #endif
27 #endif /* __cplusplus */
28
29 int array[12];
30 int 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 */
34 int 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 */