diff options
Diffstat (limited to 'test/SemaCXX/warn-literal-conversion.cpp')
-rw-r--r-- | test/SemaCXX/warn-literal-conversion.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/SemaCXX/warn-literal-conversion.cpp b/test/SemaCXX/warn-literal-conversion.cpp index 875aa1dec5efd..b607bd8c76c47 100644 --- a/test/SemaCXX/warn-literal-conversion.cpp +++ b/test/SemaCXX/warn-literal-conversion.cpp @@ -48,4 +48,15 @@ void test1() { // values. bool b3 = 0.0f; bool b4 = 0.0; + + // These all warn because they overflow the target type. + short s = 32768.0; // expected-warning{{implicit conversion of out of range value from 'double' to 'short' is undefined}} + unsigned short us = 65536.0; // expected-warning{{implicit conversion of out of range value from 'double' to 'unsigned short' is undefined}} + + short s2 = -32769.0; // expected-warning{{implicit conversion of out of range value from 'double' to 'short' is undefined}} + unsigned short us2 = -65537.0; // expected-warning{{implicit conversion of out of range value from 'double' to 'unsigned short' is undefined}} } + +int a() { return 2147483647.5; } // expected-warning{{implicit conversion from 'double' to 'int' changes value from 2147483647.5 to 2147483647}} +unsigned b() { return -.5; } // expected-warning{{implicit conversion from 'double' to 'unsigned int' changes value from -0.5 to 0}} + |