brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · e90f7b2 Raw
78 lines · c
1// RUN: %clang_cc1 -triple %itanium_abi_triple -verify -fsyntax-only -std=c11 -Wassign-enum %s2 3enum __attribute__((flag_enum)) flag {4  ea = 0x1,5  eb = 0x2,6  ec = 0x8,7};8 9enum __attribute__((flag_enum)) {10  g = 0x7,  // expected-warning {{enumeration value 'g' is out of range of flags in enumeration type 'enum (unnamed at}}11};12 13enum __attribute__((flag_enum)) flag2 {14  ga = 0x1,15  gb = 0x4,16 17  gc = 0x5, // no-warning18  gd = 0x7, // expected-warning {{enumeration value 'gd' is out of range}}19  ge = ~0x2, // expected-warning {{enumeration value 'ge' is out of range}}20  gf = ~0x4, // no-warning21  gg = ~0x1, // no-warning22  gh = ~0x5, // no-warning23  gi = ~0x11, // expected-warning {{enumeration value 'gi' is out of range}}24};25 26enum __attribute__((flag_enum)) flag3 {27  fa = 0x1,28  fb = ~0x1u, // no-warning29};30 31// What happens here is that ~0x2 is negative, and so the enum must be signed.32// But ~0x1u is unsigned and has the high bit set, so the enum must be 64-bit.33// The result is that ~0x1u does not have high bits set, and so it is considered34// to be an invalid value. See Sema::IsValueInFlagEnum in SemaDecl.cpp for more35// discussion.36enum __attribute__((flag_enum)) flag4 {37  ha = 0x1,38  hb = 0x2,39 40  hc = ~0x1u, // expected-warning {{enumeration value 'hc' is out of range}}41  hd = ~0x2, // no-warning42};43 44void f(void) {45  enum flag e = 0; // no-warning46  e = 0x1; // no-warning47  e = 0x3; // no-warning48  e = 0xa; // no-warning49  e = 0x4; // expected-warning {{integer constant not in range of enumerated type}}50  e = 0xf; // expected-warning {{integer constant not in range of enumerated type}}51  e = ~0; // no-warning52  e = ~0x1; // no-warning53  e = ~0x2; // no-warning54  e = ~0x3; // no-warning55  e = ~0x4; // expected-warning {{integer constant not in range of enumerated type}}56 57  switch (e) {58    case 0: break; // no-warning59    case 0x1: break; // no-warning60    case 0x3: break; // no-warning61    case 0xa: break; // no-warning62    case 0x4: break; // expected-warning {{case value not in enumerated type}}63    case 0xf: break; // expected-warning {{case value not in enumerated type}}64    case ~0: break; // expected-warning {{case value not in enumerated type}}65    case ~0x1: break; // expected-warning {{case value not in enumerated type}}66    case ~0x2: break; // expected-warning {{case value not in enumerated type}}67    case ~0x3: break; // expected-warning {{case value not in enumerated type}}68    case ~0x4: break; // expected-warning {{case value not in enumerated type}}69    default: break;70  }71 72  enum flag2 f = ~0x1; // no-warning73  f = ~0x1u; // no-warning74 75  enum flag4 h = ~0x1; // no-warning76  h = ~0x1u; // expected-warning {{integer constant not in range of enumerated type}}77}78