Author: rtrieu Date: Mon May 14 16:21:48 2018 New Revision: 332310 URL: http://llvm.org/viewvc/llvm-project?rev=332310&view=rev Log: Enable control flow pruning of float overflow warnings.
Like other conversion warnings, allow float overflow warnings to be disabled in known dead paths of template instantiation. This often occurs when a template template type is a numeric type and the template will check the range of the numeric type before performing the conversion. Modified: cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/SemaCXX/warn-float-conversion.cpp Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=332310&r1=332309&r2=332310&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon May 14 16:21:48 2018 @@ -9673,7 +9673,8 @@ static void DiagnoseFloatingImpCast(Sema return DiagnoseImpCast( S, E, T, CContext, IsLiteral ? diag::warn_impcast_literal_float_to_integer_out_of_range - : diag::warn_impcast_float_to_integer_out_of_range); + : diag::warn_impcast_float_to_integer_out_of_range, + PruneWarnings); unsigned DiagID = 0; if (IsLiteral) { Modified: cfe/trunk/test/SemaCXX/warn-float-conversion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-float-conversion.cpp?rev=332310&r1=332309&r2=332310&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/warn-float-conversion.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-float-conversion.cpp Mon May 14 16:21:48 2018 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits