blob: edd4e37229276276f8bf391179c82aa69db6022c [file] [log] [blame]
Fariborz Jahanian379b2812012-07-17 18:00:08 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wassign-enum %s
2// rdar://11824807
3
4typedef enum CCTestEnum
5{
6 One,
7 Two=4,
8 Three
9} CCTestEnum;
10
11CCTestEnum test = 50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
12CCTestEnum test1 = -50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
13
Stephen Hines651f13c2014-04-23 16:59:28 -070014// Explicit cast should silence the warning.
15static const CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
16static const CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning
17static const CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning
18static const CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning
19
20void SilenceWithCastLocalVar() {
21 CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
22 CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning
23 CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning
24 CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning
25
26 const CCTestEnum SilenceWithCast1c = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
27 const CCTestEnum SilenceWithCast2c = (CCTestEnum) 51; // no-warning
28 const CCTestEnum SilenceWithCast3c = (const CCTestEnum) 51; // no-warning
29 const CCTestEnum SilenceWithCast4c = (const volatile CCTestEnum) 51; // no-warning
30}
31
Fariborz Jahanian379b2812012-07-17 18:00:08 +000032CCTestEnum foo(CCTestEnum r) {
33 return 20; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
34}
35
36enum Test2 { K_zero, K_one };
37enum Test2 test2(enum Test2 *t) {
38 *t = 20; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}}
39 return 10; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}}
40}
41
Joey Gouly48a1e812013-06-06 13:48:00 +000042// PR15069
43typedef enum
44{
45 a = 0
46} T;
47
48void f()
49{
50 T x = a;
51 x += 1; // expected-warning {{integer constant not in range of enumerated type}}
52}
53
Fariborz Jahanian379b2812012-07-17 18:00:08 +000054int main() {
55 CCTestEnum test = 1; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
56 test = 600; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
57 foo(2); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
58 foo(-1); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
59 foo(4);
60 foo(Two+1);
61}
62