Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / warn-outof-range-assign-enum.c
blob23c78497b37e48263bfc9f1725099af97ef11fd9
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wassign-enum %s
3 typedef enum CCTestEnum
5 One,
6 Two=4,
7 Three
8 } CCTestEnum;
10 CCTestEnum test = 50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
11 CCTestEnum test1 = -50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
13 // Explicit cast should silence the warning.
14 static const CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
15 static const CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning
16 static const CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning
17 static const CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning
19 void SilenceWithCastLocalVar(void) {
20 CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
21 CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning
22 CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning
23 CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning
25 const CCTestEnum SilenceWithCast1c = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
26 const CCTestEnum SilenceWithCast2c = (CCTestEnum) 51; // no-warning
27 const CCTestEnum SilenceWithCast3c = (const CCTestEnum) 51; // no-warning
28 const CCTestEnum SilenceWithCast4c = (const volatile CCTestEnum) 51; // no-warning
31 CCTestEnum foo(CCTestEnum r) {
32 return 20; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
35 enum Test2 { K_zero, K_one };
36 enum Test2 test2(enum Test2 *t) {
37 *t = 20; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}}
38 return 10; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}}
41 // PR15069
42 typedef enum
44 a = 0
45 } T;
47 void f(void)
49 T x = a;
50 x += 1; // expected-warning {{integer constant not in range of enumerated type}}
53 int main(void) {
54 CCTestEnum test = 1; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
55 test = 600; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
56 foo(2); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
57 foo(-1); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}
58 foo(4);
59 foo(Two+1);