1 // RUN: %clang_cc1 -triple %itanium_abi_triple -verify -fsyntax-only -std=c11 -Wassign-enum %s
3 enum __attribute__((flag_enum
)) flag
{
9 enum __attribute__((flag_enum
)) {
10 g
= 0x7, // expected-warning {{enumeration value 'g' is out of range of flags in enumeration type ''}}
13 enum __attribute__((flag_enum
)) flag2
{
17 gc
= 0x5, // no-warning
18 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-warning
21 gg
= ~0x1, // no-warning
22 gh
= ~0x5, // no-warning
23 gi
= ~0x11, // expected-warning {{enumeration value 'gi' is out of range}}
26 enum __attribute__((flag_enum
)) flag3
{
28 fb
= ~0x1u
, // no-warning
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 considered
34 // to be an invalid value. See Sema::IsValueInFlagEnum in SemaDecl.cpp for more
36 enum __attribute__((flag_enum
)) flag4
{
40 hc
= ~0x1u
, // expected-warning {{enumeration value 'hc' is out of range}}
41 hd
= ~0x2, // no-warning
45 enum flag e
= 0; // no-warning
46 e
= 0x1; // no-warning
47 e
= 0x3; // no-warning
48 e
= 0xa; // no-warning
49 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}}
52 e
= ~0x1; // no-warning
53 e
= ~0x2; // no-warning
54 e
= ~0x3; // no-warning
55 e
= ~0x4; // expected-warning {{integer constant not in range of enumerated type}}
58 case 0: break; // no-warning
59 case 0x1: break; // no-warning
60 case 0x3: break; // no-warning
61 case 0xa: break; // no-warning
62 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}}
72 enum flag2 f
= ~0x1; // no-warning
73 f
= ~0x1u
; // no-warning
75 enum flag4 h
= ~0x1; // no-warning
76 h
= ~0x1u
; // expected-warning {{integer constant not in range of enumerated type}}