brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 3bf9537 Raw
60 lines · c
1/* RUN: %clang_cc1 -std=c99 -ffreestanding -triple x86_64-unknown-linux -fsyntax-only -verify -pedantic -Wno-c11-extensions %s2   RUN: %clang_cc1 -std=c99 -ffreestanding -triple x86_64-unknown-win32 -fms-compatibility -fsyntax-only -verify -pedantic -Wno-c11-extensions %s3   RUN: %clang_cc1 -std=c11 -ffreestanding -fsyntax-only -verify -pedantic %s4   RUN: %clang_cc1 -std=c17 -ffreestanding -fsyntax-only -verify -pedantic %s5   RUN: %clang_cc1 -std=c2x -ffreestanding -fsyntax-only -verify -pedantic %s6 */7// expected-no-diagnostics8 9/* WG14 DR209: partial10 * Problem implementing INTN_C macros11 */12#include <stdint.h>13 14#if INT8_C(0) != 015#error "uh oh"16#elif INT16_C(0) != 017#error "uh oh"18#elif INT32_C(0) != 019#error "uh oh"20#elif INT64_C(0) != 0LL21#error "uh oh"22#elif UINT8_C(0) != 0U23#error "uh oh"24#elif UINT16_C(0) != 0U25#error "uh oh"26#elif UINT32_C(0) != 0U27#error "uh oh"28#elif UINT64_C(0) != 0ULL29#error "uh oh"30#endif31 32void dr209(void) {33  (void)_Generic(INT8_C(0), __typeof__(+(int_least8_t){0}) : 1);34  (void)_Generic(INT16_C(0), __typeof__(+(int_least16_t){0}) : 1);35  (void)_Generic(INT32_C(0), __typeof__(+(int_least32_t){0}) : 1);36  (void)_Generic(INT64_C(0), __typeof__(+(int_least64_t){0}) : 1);37  // The type of the expanded value in both of these cases should be 'int',38  //39  // C99 7.18.4p3: The type of the expression shall have the same type as would40  // an expression of the corresponding type converted according to the integer41  // promotions.42  //43  // C99 7.18.4.1p1: The macro UINTN_C(value) shall expand to an integer44  // constant expression corresponding to the type uint_leastN_t.45  //46  // C99 7.18.1.2p2: The typedef name uint_leastN_t designates an unsigned47  // integer type with a width of at least N, ...48  //49  // So the value's type is the same underlying type as uint_leastN_t, which is50  // unsigned char for uint_least8_t, and unsigned short for uint_least16_t,51  // but then the value undergoes integer promotions which would convert both52  // of those types to int.53  //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  (void)_Generic(UINT32_C(0), __typeof__(+(uint_least32_t){0}) : 1);57  (void)_Generic(UINT64_C(0), __typeof__(+(uint_least64_t){0}) : 1);58}59 60