| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 %s |
| 2 |
// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 %s |
| 3 |
// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++98 %s |
| 4 |
// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 -std=c++11 %s |
| 5 |
|
| 6 |
int f(int i) { |
| 7 |
switch (i) { |
| 8 |
case 2147483647 + 2: |
| 9 |
#if (__cplusplus <= 199711L) // C or C++03 or earlier modes |
| 10 |
// expected-warning@-2 {{overflow in expression; result is -2'147'483'647 with type 'int'}} |
| 11 |
#else |
| 12 |
// 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 |
#endif |
| 15 |
return 1; |
| 16 |
case 9223372036854775807L * 4: |
| 17 |
#if (__cplusplus <= 199711L) |
| 18 |
// expected-warning@-2 {{overflow in expression; result is -4 with type 'long'}} |
| 19 |
#else |
| 20 |
// 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 |
#endif |
| 23 |
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 |
#else |
| 28 |
// 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 |
#endif |
| 31 |
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 |
#else |
| 36 |
// 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 |
#endif |
| 39 |
case (2147483647*4)%4: |
| 40 |
#if (__cplusplus <= 199711L) |
| 41 |
// expected-warning@-2 {{overflow in expression; result is -4 with type 'int'}} |
| 42 |
#else |
| 43 |
// 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 |
#endif |
| 46 |
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 |
|
| 54 |
unsigned long long l = 65536 * 65536; // expected-warning {{overflow in expression; result is 0 with type 'int'}} |
| 55 |
unsigned long long l2 = 65536 * (unsigned)65536; |
| 56 |
unsigned long long l3 = 65536 * 65536ULL; |