Testcase:
int
main() {
double x = 1.0, y = 2.0;
decltype(x == y) b{};
(void) b;
}
With current Clang, the code above produces a warning:
/tmp/foo.cpp:4:14: warning: comparing floating point with == or != is unsafe
[-Wfloat-equal]
decltype(x == y) b{};
That warning is clearly useless as we are in an unevaluated context
here. This patch suppresses this warning in these contexts.
There is no test for this patch, because I couldn't find any suitable
test file to add it to. I'll be happy to add one if you can suggest a
proper place for it.
~ Ondra
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index c28325a..1da7984 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -5354,6 +5354,10 @@ void Sema::CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr *RHS) {
if (CR->getBuiltinCallee())
return;
+ // Don't warn in unevaluated constexts, such as inside decltype.
+ if (ExprEvalContexts.back().Context == Sema::Unevaluated)
+ return;
+
// Emit the diagnostic.
Diag(Loc, diag::warn_floatingpoint_eq)
<< LHS->getSourceRange() << RHS->getSourceRange();
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits