diff options
Diffstat (limited to 'clang/test/Sema/constant-conversion.c')
-rw-r--r-- | clang/test/Sema/constant-conversion.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/clang/test/Sema/constant-conversion.c b/clang/test/Sema/constant-conversion.c index 13763339671..74a469d08a9 100644 --- a/clang/test/Sema/constant-conversion.c +++ b/clang/test/Sema/constant-conversion.c @@ -80,3 +80,34 @@ void test8() { struct { enum E x : 1; } f; f.x = C; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 2 to 0}} } + +void test9() { + const char max_char = 0x7F; + const short max_short = 0x7FFF; + const int max_int = 0x7FFFFFFF; + + const short max_char_plus_one = (short)max_char + 1; + const int max_short_plus_one = (int)max_short + 1; + const long max_int_plus_one = (long)max_int + 1; + + char new_char = max_char_plus_one; // expected-warning {{implicit conversion from 'const short' to 'char' changes value from 128 to -128}} + short new_short = max_short_plus_one; // expected-warning {{implicit conversion from 'const int' to 'short' changes value from 32768 to -32768}} + int new_int = max_int_plus_one; // expected-warning {{implicit conversion from 'const long' to 'int' changes value from 2147483648 to -2147483648}} + + char hex_char = 0x80; + short hex_short = 0x8000; + int hex_int = 0x80000000; + + char oct_char = 0200; + short oct_short = 0100000; + int oct_int = 020000000000; + + char bin_char = 0b10000000; + short bin_short = 0b1000000000000000; + int bin_int = 0b10000000000000000000000000000000; + +#define CHAR_MACRO_HEX 0xff + char macro_char_hex = CHAR_MACRO_HEX; +#define CHAR_MACRO_DEC 255 + char macro_char_dec = CHAR_MACRO_DEC; // expected-warning {{implicit conversion from 'int' to 'char' changes value from 255 to -1}} +} |