diff options
author | Matt Beaumont-Gay <matthewbg@google.com> | 2011-09-08 22:30:47 +0000 |
---|---|---|
committer | Matt Beaumont-Gay <matthewbg@google.com> | 2011-09-08 22:30:47 +0000 |
commit | 634c8af0805ba33b1530470e03aa314141036aa2 (patch) | |
tree | e747d3de206ee81df524bc294f8121b42bf81228 | |
parent | 8bccabeac6b98650dfd88bd1fc84e841eb42af4b (diff) |
Extend -Wliteral-conversion to catch "int i = -1.234"
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139326 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 5 | ||||
-rw-r--r-- | test/SemaCXX/warn-literal-conversion.cpp | 3 |
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index f5dec069cc..aec90bd9ce 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -3287,6 +3287,11 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T, return; Expr *InnerE = E->IgnoreParenImpCasts(); + // We also want to warn on, e.g., "int i = -1.234" + if (UnaryOperator *UOp = dyn_cast<UnaryOperator>(InnerE)) + if (UOp->getOpcode() == UO_Minus || UOp->getOpcode() == UO_Plus) + InnerE = UOp->getSubExpr()->IgnoreParenImpCasts(); + if (FloatingLiteral *FL = dyn_cast<FloatingLiteral>(InnerE)) { DiagnoseFloatingLiteralImpCast(S, FL, T, CC); } else { diff --git a/test/SemaCXX/warn-literal-conversion.cpp b/test/SemaCXX/warn-literal-conversion.cpp index b9c952873b..3fc8a6fec7 100644 --- a/test/SemaCXX/warn-literal-conversion.cpp +++ b/test/SemaCXX/warn-literal-conversion.cpp @@ -30,8 +30,7 @@ void test0() { // Test passing a literal floating-point value to a function that takes an integer. foo(1.2F); // expected-warning {{implicit conversion turns literal floating-point number into integer}} - // FIXME: -Wconversion-literal doesn't catch "-1.2F". - int y10 = -1.2F; + int y10 = -1.2F; // expected-warning {{implicit conversion turns literal floating-point number into integer}} // -Wconversion-literal does NOT catch const values. // (-Wconversion DOES catch them.) |