Debian Codegraph @

clang/test/C/C2y/n3457.c

raw
1 // RUN: %clang_cc1 -verify=ext -std=c23 -pedantic %s
2 // RUN: %clang_cc1 -verify=ext -pedantic -x c++ %s
3 // RUN: %clang_cc1 -verify=pre -std=c2y -pedantic -Wpre-c2y-compat %s
4
5 /* WG14 N3457: Clang 22
6 * The __COUNTER__ predefined macro
7 *
8 * This predefined macro was supported as an extension in earlier versions of
9 * Clang, but the required diagnostics for the limits were not added until 22.
10 */
11
12 // Ensure that __COUNTER__ starts from 0.
13 static_assert(__COUNTER__ == 0); /* ext-warning {{'__COUNTER__' is a C2y extension}}
14 pre-warning {{'__COUNTER__' is incompatible with standards before C2y}}
15 */
16
17 // Ensure that the produced value can be used with token concatenation.
18 #define CAT_IMPL(a, b) a ## b
19 #define CAT(a, b) CAT_IMPL(a, b)
20 #define NAME_WITH_COUNTER(a) CAT(a, __COUNTER__)
21 void test() {
22 // Because this is the 2nd expansion, this defines test1.
23 int NAME_WITH_COUNTER(test); /* ext-warning {{'__COUNTER__' is a C2y extension}}
24 pre-warning {{'__COUNTER__' is incompatible with standards before C2y}}
25 */
26 int other_test = test1; // Ok
27 }
28
29 // Ensure that __COUNTER__ increments each time you mention it.
30 static_assert(__COUNTER__ == 2); /* ext-warning {{'__COUNTER__' is a C2y extension}}
31 pre-warning {{'__COUNTER__' is incompatible with standards before C2y}}
32 */
33 static_assert(__COUNTER__ == 3); /* ext-warning {{'__COUNTER__' is a C2y extension}}
34 pre-warning {{'__COUNTER__' is incompatible with standards before C2y}}
35 */
36 static_assert(__COUNTER__ == 4); /* ext-warning {{'__COUNTER__' is a C2y extension}}
37 pre-warning {{'__COUNTER__' is incompatible with standards before C2y}}
38 */