
WG14 adopted N2775 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2775.pdf) at our Feb 2022 meeting. This paper adds a literal suffix for bit-precise types that automatically sizes the bit-precise type to be the smallest possible legal _BitInt type that can represent the literal value. The suffix chosen is wb (for a signed bit-precise type) which can be combined with the u suffix (for an unsigned bit-precise type). The preprocessor continues to operate as-if all integer types were intmax_t/uintmax_t, including bit-precise integer types. It is a constraint violation if the bit-precise literal is too large to fit within that type in the context of the preprocessor (when still using a pp-number preprocessing token), but it is not a constraint violation in other circumstances. This allows you to make bit-precise integer literals that are wider than what the preprocessor currently supports in order to initialize variables, etc.
15 lines
867 B
C
15 lines
867 B
C
// RUN: %clang_cc1 -std=c17 -fsyntax-only -verify=ext -Wno-unused %s
|
|
// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=compat -Wpre-c2x-compat -Wno-unused %s
|
|
// RUN: %clang_cc1 -fsyntax-only -verify=cpp -Wno-unused -x c++ %s
|
|
|
|
#if 18446744073709551615uwb // ext-warning {{'_BitInt' suffix for literals is a C2x extension}} \
|
|
compat-warning {{'_BitInt' suffix for literals is incompatible with C standards before C2x}} \
|
|
cpp-error {{invalid suffix 'uwb' on integer constant}}
|
|
#endif
|
|
|
|
void func(void) {
|
|
18446744073709551615wb; // ext-warning {{'_BitInt' suffix for literals is a C2x extension}} \
|
|
compat-warning {{'_BitInt' suffix for literals is incompatible with C standards before C2x}} \
|
|
cpp-error {{invalid suffix 'wb' on integer constant}}
|
|
}
|