| 1 |
// RUN: %clang_cc1 -E -verify %s |
| 2 |
|
| 3 |
// C++ [lex.icon]p4 and C 6.4.4.1p2 + 6.4.4.2p7 both require C and C++ to |
| 4 |
// validate the integer constant value when converting a preprocessing token |
| 5 |
// into a token for semantic analysis, even within the preprocessor itself. |
| 6 |
|
| 7 |
// Plain integer constant. |
| 8 |
#if 999999999999999999999 // expected-error {{integer literal is too large to be represented in any integer type}} |
| 9 |
#endif |
| 10 |
|
| 11 |
// These cases were previously incorrectly accepted. See GH134658. |
| 12 |
|
| 13 |
// Integer constant in an unevaluated branch of a conditional. |
| 14 |
#if 1 ? 1 : 999999999999999999999 // expected-error {{integer literal is too large to be represented in any integer type}} |
| 15 |
#endif |
| 16 |
|
| 17 |
// Integer constant in an unevaluated operand of a logical operator. |
| 18 |
#if 0 && 999999999999999999999 // expected-error {{integer literal is too large to be represented in any integer type}} |
| 19 |
#endif |
| 20 |
|
| 21 |
#if 1 || 999999999999999999999 // expected-error {{integer literal is too large to be represented in any integer type}} |
| 22 |
#endif |
| 23 |
|
| 24 |
// Make sure we also catch it in an elif condition. |
| 25 |
#if 0 |
| 26 |
#elif 1 || 999999999999999999999 // expected-error {{integer literal is too large to be represented in any integer type}} |
| 27 |
#endif |
| 28 |
|
| 29 |
// However, if the block is skipped entirely, then it doesn't matter how |
| 30 |
// invalid the constant value is. |
| 31 |
#if 0 |
| 32 |
int x = 999999999999999999999; |
| 33 |
|
| 34 |
#if 999999999999999999999 |
| 35 |
#endif |
| 36 |
|
| 37 |
#if 0 && 999999999999999999999 |
| 38 |
#endif |
| 39 |
|
| 40 |
#endif |