diff options
Diffstat (limited to 'clang/test/SemaCXX/warn-float-conversion.cpp')
-rw-r--r-- | clang/test/SemaCXX/warn-float-conversion.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/warn-float-conversion.cpp b/clang/test/SemaCXX/warn-float-conversion.cpp index 2e89acb3d68..a3d178622c7 100644 --- a/clang/test/SemaCXX/warn-float-conversion.cpp +++ b/clang/test/SemaCXX/warn-float-conversion.cpp @@ -89,4 +89,38 @@ void TestOverflow() { 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; } + +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 |