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 | a5b9332418f25338f118358e27303cd510d54107 (patch) | |
tree | cb55620c4d75353ba842dbd80ae084e6a13c47ef /lib | |
parent | 56ca35d396d8692c384c785f9aeebcf22563fe1e (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125745 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 9913edb434..a3ab52c000 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/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; } |