• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 %s -fsyntax-only -verify -Wduplicate-enum
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -x c++ -DCPP -fsyntax-only -verify -Wduplicate-enum
3 enum A {
4   A1 = 0,  // expected-note {{element 'A1' also has value 0}}
5   A2 = -1,
6   A3,  // expected-warning {{element 'A3' has been implicitly assigned 0 which another element has been assigned}}
7   A4};
8 
9 enum B {
10   B1 = -1,  // expected-note {{element 'B1' also has value -1}}
11   B2,       // expected-warning {{element 'B2' has been implicitly assigned 0 which another element has been assigned}}
12   B3,
13   B4 = -2,
14   B5,  // expected-warning {{element 'B5' has been implicitly assigned -1 which another element has been assigned}}
15   B6   // expected-note {{element 'B6' also has value 0}}
16 };
17 
18 enum C { C1, C2 = -1, C3 }; // expected-warning{{element 'C1' has been implicitly assigned 0 which another element has been assigned}} \
19   // expected-note {{element 'C3' also has value 0}}
20 
21 enum D {
22   D1,
23   D2,
24   D3,  // expected-warning{{element 'D3' has been implicitly assigned 2 which another element has been assigned}}
25   D4 = D2,  // no warning
26   D5 = 2  // expected-note {{element 'D5' also has value 2}}
27 };
28 
29 enum E {
30   E1,
31   E2 = E1,
32   E3 = E2
33 };
34 
35 enum F {
36   F1,
37   F2,
38   FCount,
39   FMax = FCount - 1
40 };
41 
42 enum G {
43   G1,
44   G2,
45   GMax = G2,
46   GCount = GMax + 1
47 };
48 
49 enum {
50   H1 = 0,
51   H2 = -1,
52   H3,
53   H4};
54 
55 enum {
56   I1 = -1,
57   I2,
58   I3,
59   I4 = -2,
60   I5,
61   I6
62 };
63 
64 enum { J1, J2 = -1, J3 };
65 
66 enum {
67   K1,
68   K2,
69   K3,
70   K4 = K2,
71   K5 = 2
72 };
73 
74 enum {
75   L1,
76   L2 = L1,
77   L3 = L2
78 };
79 
80 enum {
81   M1,
82   M2,
83   MCount,
84   MMax = MCount - 1
85 };
86 
87 enum {
88   N1,
89   N2,
90   NMax = N2,
91   NCount = NMax + 1
92 };
93 
94 // PR15693
95 enum enum1 {
96   VALUE // expected-note{{previous definition is here}}
97 };
98 
99 enum enum2 {
100   VALUE // expected-error{{redefinition of enumerator 'VALUE'}}
101 };
102 
103 // rdar://44774672
104 #ifdef CPP
105 enum BigEnumerators : long {
106   e1,
107   e2 = __LONG_MAX__,
108 };
109 #endif
110