1 // RUN: %clang_cc1 -fsyntax-only -verify -Wassign-enum %s
3 typedef enum 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'}}
50 x
+= 1; // expected-warning {{integer constant not in range of enumerated type}}
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'}}