62 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify -Wassign-enum %s2 3typedef enum CCTestEnum4{5 One,6 Two=4,7 Three8} CCTestEnum;9 10CCTestEnum test = 50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}11CCTestEnum test1 = -50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}12 13// Explicit cast should silence the warning.14static const CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}15static const CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning16static const CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning17static const CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning18 19void SilenceWithCastLocalVar(void) {20 CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}21 CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning22 CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning23 CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning24 25 const CCTestEnum SilenceWithCast1c = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}26 const CCTestEnum SilenceWithCast2c = (CCTestEnum) 51; // no-warning27 const CCTestEnum SilenceWithCast3c = (const CCTestEnum) 51; // no-warning28 const CCTestEnum SilenceWithCast4c = (const volatile CCTestEnum) 51; // no-warning29}30 31CCTestEnum foo(CCTestEnum r) {32 return 20; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}}33}34 35enum Test2 { K_zero, K_one };36enum 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'}}39}40 41// PR1506942typedef enum43{44 a = 045} T;46 47void f(void)48{49 T x = a;50 x += 1; // expected-warning {{integer constant not in range of enumerated type}}51}52 53int 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);60}61 62