1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -Wassign-enum %s 2*67e74705SXin Li // rdar://11824807 3*67e74705SXin Li 4*67e74705SXin Li typedef enum CCTestEnum 5*67e74705SXin Li { 6*67e74705SXin Li One, 7*67e74705SXin Li Two=4, 8*67e74705SXin Li Three 9*67e74705SXin Li } CCTestEnum; 10*67e74705SXin Li 11*67e74705SXin Li CCTestEnum test = 50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 12*67e74705SXin Li CCTestEnum test1 = -50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 13*67e74705SXin Li 14*67e74705SXin Li // Explicit cast should silence the warning. 15*67e74705SXin Li static const CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 16*67e74705SXin Li static const CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning 17*67e74705SXin Li static const CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning 18*67e74705SXin Li static const CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning 19*67e74705SXin Li SilenceWithCastLocalVar()20*67e74705SXin Livoid SilenceWithCastLocalVar() { 21*67e74705SXin Li CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 22*67e74705SXin Li CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning 23*67e74705SXin Li CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning 24*67e74705SXin Li CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning 25*67e74705SXin Li 26*67e74705SXin Li const CCTestEnum SilenceWithCast1c = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 27*67e74705SXin Li const CCTestEnum SilenceWithCast2c = (CCTestEnum) 51; // no-warning 28*67e74705SXin Li const CCTestEnum SilenceWithCast3c = (const CCTestEnum) 51; // no-warning 29*67e74705SXin Li const CCTestEnum SilenceWithCast4c = (const volatile CCTestEnum) 51; // no-warning 30*67e74705SXin Li } 31*67e74705SXin Li foo(CCTestEnum r)32*67e74705SXin LiCCTestEnum foo(CCTestEnum r) { 33*67e74705SXin Li return 20; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 34*67e74705SXin Li } 35*67e74705SXin Li 36*67e74705SXin Li enum Test2 { K_zero, K_one }; test2(enum Test2 * t)37*67e74705SXin Lienum Test2 test2(enum Test2 *t) { 38*67e74705SXin Li *t = 20; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}} 39*67e74705SXin Li return 10; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}} 40*67e74705SXin Li } 41*67e74705SXin Li 42*67e74705SXin Li // PR15069 43*67e74705SXin Li typedef enum 44*67e74705SXin Li { 45*67e74705SXin Li a = 0 46*67e74705SXin Li } T; 47*67e74705SXin Li f()48*67e74705SXin Livoid f() 49*67e74705SXin Li { 50*67e74705SXin Li T x = a; 51*67e74705SXin Li x += 1; // expected-warning {{integer constant not in range of enumerated type}} 52*67e74705SXin Li } 53*67e74705SXin Li main()54*67e74705SXin Liint main() { 55*67e74705SXin Li CCTestEnum test = 1; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 56*67e74705SXin Li test = 600; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 57*67e74705SXin Li foo(2); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 58*67e74705SXin Li foo(-1); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} 59*67e74705SXin Li foo(4); 60*67e74705SXin Li foo(Two+1); 61*67e74705SXin Li } 62*67e74705SXin Li 63