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