diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-02-17 11:05:49 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-02-17 11:05:49 +0000 |
commit | 22c7a79a1da4abd46e1e2f9cbe21f4242853d8dc (patch) | |
tree | 0322740d38851d68f1a6654d06849de2e1d9772c /clang/lib/Sema/SemaChecking.cpp | |
parent | c07a0c7e483cf6b157295dcc18bfb782e3424591 (diff) | |
download | bcm5719-llvm-22c7a79a1da4abd46e1e2f9cbe21f4242853d8dc.tar.gz bcm5719-llvm-22c7a79a1da4abd46e1e2f9cbe21f4242853d8dc.zip |
Implement a sub-group of -Wconversion: -Wliteral-conversion. This
specifically targets literals which are implicitly converted, a those
are more often unintended and trivial to fix. This can be especially
helpful for diagnosing what makes 'const int x = 1e6' not an ICE.
Original patch authored by Jim Meehan with contributions from other
Googlers and a few cleanups from myself.
llvm-svn: 125745
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 9913edb4347..a3ab52c0006 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -2799,9 +2799,15 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T, } // If the target is integral, always warn. - if ((TargetBT && TargetBT->isInteger())) - // TODO: don't warn for integer values? - DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_float_integer); + if ((TargetBT && TargetBT->isInteger())) { + Expr *InnerE = E->IgnoreParenImpCasts(); + if (FloatingLiteral *LiteralExpr = dyn_cast<FloatingLiteral>(InnerE)) { + DiagnoseImpCast(S, LiteralExpr, T, CC, + diag::warn_impcast_literal_float_to_integer); + } else { + DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_float_integer); + } + } return; } |