1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 %s 2*67e74705SXin Li // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 %s 3*67e74705SXin Li // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++98 %s 4*67e74705SXin Li // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++11 %s 5*67e74705SXin Li // rdar://11577384 6*67e74705SXin Li // rdar://13423975 7*67e74705SXin Li f(int i)8*67e74705SXin Liint f(int i) { 9*67e74705SXin Li switch (i) { 10*67e74705SXin Li case 2147483647 + 2: 11*67e74705SXin Li #if (__cplusplus <= 199711L) // C or C++03 or earlier modes 12*67e74705SXin Li // expected-warning@-2 {{overflow in expression; result is -2147483647 with type 'int'}} 13*67e74705SXin Li #else 14*67e74705SXin Li // expected-error@-4 {{case value is not a constant expression}} \ 15*67e74705SXin Li // expected-note@-4 {{value 2147483649 is outside the range of representable values of type 'int'}} 16*67e74705SXin Li #endif 17*67e74705SXin Li return 1; 18*67e74705SXin Li case 9223372036854775807L * 4: 19*67e74705SXin Li #if (__cplusplus <= 199711L) 20*67e74705SXin Li // expected-warning@-2 {{overflow in expression; result is -4 with type 'long'}} 21*67e74705SXin Li #else 22*67e74705SXin Li // expected-error@-4 {{case value is not a constant expression}} \ 23*67e74705SXin Li // expected-note@-4 {{value 36893488147419103228 is outside the range of representable values of type 'long'}} 24*67e74705SXin Li #endif 25*67e74705SXin Li return 2; 26*67e74705SXin Li case (123456 *789012) + 1: 27*67e74705SXin Li #if (__cplusplus <= 199711L) 28*67e74705SXin Li // expected-warning@-2 {{overflow in expression; result is -1375982336 with type 'int'}} 29*67e74705SXin Li #else 30*67e74705SXin Li // expected-error@-4 {{case value is not a constant expression}} \ 31*67e74705SXin Li // expected-note@-4 {{value 97408265472 is outside the range of representable values of type 'int'}} 32*67e74705SXin Li #endif 33*67e74705SXin Li return 3; 34*67e74705SXin Li case (2147483647*4)/4: 35*67e74705SXin Li #if (__cplusplus <= 199711L) 36*67e74705SXin Li // expected-warning@-2 {{overflow in expression; result is -4 with type 'int'}} 37*67e74705SXin Li #else 38*67e74705SXin Li // expected-error@-4 {{case value is not a constant expression}} \ 39*67e74705SXin Li // expected-note@-4 {{value 8589934588 is outside the range of representable values of type 'int'}} 40*67e74705SXin Li #endif 41*67e74705SXin Li case (2147483647*4)%4: 42*67e74705SXin Li #if (__cplusplus <= 199711L) 43*67e74705SXin Li // expected-warning@-2 {{overflow in expression; result is -4 with type 'int'}} 44*67e74705SXin Li #else 45*67e74705SXin Li // expected-error@-4 {{case value is not a constant expression}} \ 46*67e74705SXin Li // expected-note@-4 {{value 8589934588 is outside the range of representable values of type 'int'}} 47*67e74705SXin Li #endif 48*67e74705SXin Li return 4; 49*67e74705SXin Li case 2147483647: 50*67e74705SXin Li return 0; 51*67e74705SXin Li } 52*67e74705SXin Li return (i, 65537) * 65537; // expected-warning {{overflow in expression; result is 131073 with type 'int'}} \ 53*67e74705SXin Li // expected-warning {{expression result unused}} 54*67e74705SXin Li } 55*67e74705SXin Li 56*67e74705SXin Li // rdar://18405357 57*67e74705SXin Li unsigned long long l = 65536 * 65536; // expected-warning {{overflow in expression; result is 0 with type 'int'}} 58*67e74705SXin Li unsigned long long l2 = 65536 * (unsigned)65536; 59*67e74705SXin Li unsigned long long l3 = 65536 * 65536ULL; 60