[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / C / drs / dr209.c
blobd8613669f327777f7e6d8b3380860975e842cda0
1 /* RUN: %clang_cc1 -std=c99 -ffreestanding -triple x86_64-unknown-linux -fsyntax-only -verify -pedantic -Wno-c11-extensions %s
2 RUN: %clang_cc1 -std=c99 -ffreestanding -triple x86_64-unknown-win32 -fms-compatibility -fsyntax-only -verify -pedantic -Wno-c11-extensions %s
3 RUN: %clang_cc1 -std=c11 -ffreestanding -fsyntax-only -verify -pedantic %s
4 RUN: %clang_cc1 -std=c17 -ffreestanding -fsyntax-only -verify -pedantic %s
5 RUN: %clang_cc1 -std=c2x -ffreestanding -fsyntax-only -verify -pedantic %s
6 */
8 /* WG14 DR209: partial
9 * Problem implementing INTN_C macros
11 #include <stdint.h>
13 #if INT8_C(0) != 0
14 #error "uh oh"
15 #elif INT16_C(0) != 0
16 #error "uh oh"
17 #elif INT32_C(0) != 0
18 #error "uh oh"
19 #elif INT64_C(0) != 0LL
20 #error "uh oh"
21 #elif UINT8_C(0) != 0U
22 #error "uh oh"
23 #elif UINT16_C(0) != 0U
24 #error "uh oh"
25 #elif UINT32_C(0) != 0U
26 #error "uh oh"
27 #elif UINT64_C(0) != 0ULL
28 #error "uh oh"
29 #endif
31 void dr209(void) {
32 (void)_Generic(INT8_C(0), __typeof__(+(int_least8_t){0}) : 1);
33 (void)_Generic(INT16_C(0), __typeof__(+(int_least16_t){0}) : 1);
34 (void)_Generic(INT32_C(0), __typeof__(+(int_least32_t){0}) : 1);
35 (void)_Generic(INT64_C(0), __typeof__(+(int_least64_t){0}) : 1);
36 // FIXME: This is not the expected behavior; the type of the expanded value
37 // in both of these cases should be 'int',
39 // C99 7.18.4p3: The type of the expression shall have the same type as would
40 // an expression of the corresponding type converted according to the integer
41 // promotions.
43 // C99 7.18.4.1p1: The macro UINTN_C(value) shall expand to an integer
44 // constant expression corresponding to the type uint_leastN_t.
46 // C99 7.18.1.2p2: The typedef name uint_leastN_t designates an unsigned
47 // integer type with a width of at least N, ...
49 // So the value's type is the same underlying type as uint_leastN_t, which is
50 // unsigned char for uint_least8_t, and unsigned short for uint_least16_t,
51 // but then the value undergoes integer promotions which would convert both
52 // of those types to int.
54 (void)_Generic(UINT8_C(0), __typeof__(+(uint_least8_t){0}) : 1);
55 (void)_Generic(UINT16_C(0), __typeof__(+(uint_least16_t){0}) : 1);
56 // expected-error@-2 {{controlling expression type 'unsigned int' not compatible with any generic association type}}
57 // expected-error@-2 {{controlling expression type 'unsigned int' not compatible with any generic association type}}
58 (void)_Generic(UINT32_C(0), __typeof__(+(uint_least32_t){0}) : 1);
59 (void)_Generic(UINT64_C(0), __typeof__(+(uint_least64_t){0}) : 1);