summaryrefslogtreecommitdiff
path: root/test/SemaCXX/warn-float-conversion.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 11:06:01 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 11:06:01 +0000
commit486754660bb926339aefcf012a3f848592babb8b (patch)
treeecdbc446c9876f4f120f701c243373cd3cb43db3 /test/SemaCXX/warn-float-conversion.cpp
parent55e6d896ad333f07bb3b1ba487df214fc268a4ab (diff)
Notes
Diffstat (limited to 'test/SemaCXX/warn-float-conversion.cpp')
-rw-r--r--test/SemaCXX/warn-float-conversion.cpp43
1 files changed, 40 insertions, 3 deletions
diff --git a/test/SemaCXX/warn-float-conversion.cpp b/test/SemaCXX/warn-float-conversion.cpp
index fc221893aeee..a3d178622c7d 100644
--- a/test/SemaCXX/warn-float-conversion.cpp
+++ b/test/SemaCXX/warn-float-conversion.cpp
@@ -63,6 +63,9 @@ void TestConstantFloat() {
int b3 = five / 1.0; //expected-warning{{conversion}}
int b4 = five / 2.0; //expected-warning{{conversion}}
+
+ int f = 2147483646.5 + 1; // expected-warning{{implicit conversion from 'double' to 'int' changes value from 2147483647.5 to 2147483647}}
+ unsigned g = -.5 + .01; // expected-warning{{implicit conversion from 'double' to 'unsigned int' changes non-zero value from -0.49 to 0}}
}
#endif // FLOAT_CONVERSION
@@ -81,9 +84,43 @@ void TestOverflow() {
char b = -500.0; // caught by -Wliteral-conversion
const float LargeNumber = 1024;
- char c = LargeNumber; // expected-warning{{implicit conversion of out of range value from 'const float' to 'char' changes value from 1024 to 127}}
- char d = 400.0 + 400.0; // expected-warning{{implicit conversion of out of range value from 'double' to 'char' changes value from 800 to 127}}
+ char c = LargeNumber; // expected-warning{{implicit conversion of out of range value from 'const float' to 'char' is undefined}}
+ char d = 400.0 + 400.0; // expected-warning{{implicit conversion of out of range value from 'double' to 'char' is undefined}}
+
+ char e = 1.0 / 0.0; // expected-warning{{implicit conversion of out of range value from 'double' to 'char' is undefined}}
+}
+
+
+template <typename T>
+class Check {
+ public:
+ static constexpr bool Safe();
+};
+
+template<>
+constexpr bool Check<char>::Safe() { return false; }
- char e = 1.0 / 0.0; // expected-warning{{implicit conversion of out of range value from 'double' to 'char' changes value from +Inf to 127}}
+template<>
+constexpr bool Check<float>::Safe() { return true; }
+
+template <typename T>
+T run1(T t) {
+ const float ret = 800;
+ return ret; // expected-warning {{implicit conversion of out of range value from 'const float' to 'char' is undefined}}
+}
+
+template <typename T>
+T run2(T t) {
+ const float ret = 800;
+ if (Check<T>::Safe())
+ return ret;
+ else
+ return t;
}
+
+void test() {
+ float a = run1(a) + run2(a);
+ char b = run1(b) + run2(b); // expected-note {{in instantiation of function template specialization 'run1<char>' requested here}}
+}
+
#endif // OVERFLOW