Debian Codegraph @

clang/test/C/C2y/n3457_1.c

raw
1 // RUN: %clang_cc1 -verify -std=c2y -finitial-counter-value=2147483646 %s
2
3 // The value produced needs to be a type that's representable with a signed
4 // long. However, the actual type it expands to does *not* need to be forced to
5 // be signed long because that would generally mean suffixing the value with L,
6 // which would be very surprising for folks using this to generate unique ids.
7 // We'll test this by ensuring the largest value can be expanded properly and
8 // an assertion that signed long is always at least four bytes wide (which is
9 // what's required to represent that maximal value).
10 //
11 // So we set the initial counter value to 2147483646, we'll validate that,
12 // increment it once to get to the maximal value and ensure there's no
13 // diagnostic, then increment again to ensure we get the constraint violation.
14
15 static_assert(__COUNTER__ == 2147483646); // Test and increment
16 static_assert(__COUNTER__ == 2147483647); // Test and increment
17
18 // This one should fail.
19 signed long i = __COUNTER__; // expected-error {{'__COUNTER__' value cannot exceed 2'147'483'647}}
20