57 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 %s2// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 %s3// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++98 %s4// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++11 %s5 6int f(int i) {7 switch (i) {8 case 2147483647 + 2:9#if (__cplusplus <= 199711L) // C or C++03 or earlier modes10 // expected-warning@-2 {{overflow in expression; result is -2'147'483'647 with type 'int'}}11#else12 // expected-error@-4 {{case value is not a constant expression}} \13 // expected-note@-4 {{value 2147483649 is outside the range of representable values of type 'int'}}14#endif15 return 1;16 case 9223372036854775807L * 4:17#if (__cplusplus <= 199711L)18 // expected-warning@-2 {{overflow in expression; result is -4 with type 'long'}}19#else20 // expected-error@-4 {{case value is not a constant expression}} \21 // expected-note@-4 {{value 36893488147419103228 is outside the range of representable values of type 'long'}}22#endif23 return 2;24 case (123456 *789012) + 1:25#if (__cplusplus <= 199711L)26 // expected-warning@-2 {{overflow in expression; result is -1'375'982'336 with type 'int'}}27#else28 // expected-error@-4 {{case value is not a constant expression}} \29 // expected-note@-4 {{value 97408265472 is outside the range of representable values of type 'int'}}30#endif31 return 3;32 case (2147483647*4)/4:33#if (__cplusplus <= 199711L)34 // expected-warning@-2 {{overflow in expression; result is -4 with type 'int'}}35#else36 // expected-error@-4 {{case value is not a constant expression}} \37 // expected-note@-4 {{value 8589934588 is outside the range of representable values of type 'int'}}38#endif39 case (2147483647*4)%4:40#if (__cplusplus <= 199711L)41 // expected-warning@-2 {{overflow in expression; result is -4 with type 'int'}}42#else43 // expected-error@-4 {{case value is not a constant expression}} \44 // expected-note@-4 {{value 8589934588 is outside the range of representable values of type 'int'}}45#endif46 return 4;47 case 2147483647:48 return 0;49 }50 return (i, 65537) * 65537; // expected-warning {{overflow in expression; result is 131'073 with type 'int'}} \51 // expected-warning {{left operand of comma operator has no effect}}52}53 54unsigned long long l = 65536 * 65536; // expected-warning {{overflow in expression; result is 0 with type 'int'}}55unsigned long long l2 = 65536 * (unsigned)65536;56unsigned long long l3 = 65536 * 65536ULL;57