diff options
author | Matt Beaumont-Gay <matthewbg@google.com> | 2011-10-14 15:36:25 +0000 |
---|---|---|
committer | Matt Beaumont-Gay <matthewbg@google.com> | 2011-10-14 15:36:25 +0000 |
commit | c622163b0f7390b7b202c4aa602d5ef224478e10 (patch) | |
tree | 8567c7f28bab73d89e2acc5f280bad3dfa47986c /clang/lib/Sema/SemaChecking.cpp | |
parent | 041b084f736e875a24e3a089268e8b4747ac363e (diff) | |
download | bcm5719-llvm-c622163b0f7390b7b202c4aa602d5ef224478e10.tar.gz bcm5719-llvm-c622163b0f7390b7b202c4aa602d5ef224478e10.zip |
Only warn in -Wliteral-conversion if the conversion loses information
llvm-svn: 141955
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e95feacbab5..74c69a3ce34 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3378,34 +3378,22 @@ void DiagnoseImpCast(Sema &S, Expr *E, QualType T, SourceLocation CContext, DiagnoseImpCast(S, E, E->getType(), T, CContext, diag); } -/// Diagnose an implicit cast from a literal expression. Also attemps to supply -/// fixit hints when the cast wouldn't lose information to simply write the -/// expression with the expected type. +/// Diagnose an implicit cast from a literal expression. Does not warn when the +/// cast wouldn't lose information. void DiagnoseFloatingLiteralImpCast(Sema &S, FloatingLiteral *FL, QualType T, SourceLocation CContext) { - // Emit the primary warning first, then try to emit a fixit hint note if - // reasonable. - S.Diag(FL->getExprLoc(), diag::warn_impcast_literal_float_to_integer) - << FL->getType() << T << FL->getSourceRange() << SourceRange(CContext); - - const llvm::APFloat &Value = FL->getValue(); - - // Don't attempt to fix PPC double double literals. - if (&Value.getSemantics() == &llvm::APFloat::PPCDoubleDouble) - return; - - // Try to convert this exactly to an integer. + // Try to convert the literal exactly to an integer. If we can, don't warn. bool isExact = false; + const llvm::APFloat &Value = FL->getValue(); llvm::APSInt IntegerValue(S.Context.getIntWidth(T), T->hasUnsignedIntegerRepresentation()); if (Value.convertToInteger(IntegerValue, llvm::APFloat::rmTowardZero, &isExact) - != llvm::APFloat::opOK || !isExact) + == llvm::APFloat::opOK && isExact) return; - std::string LiteralValue = IntegerValue.toString(10); - S.Diag(FL->getExprLoc(), diag::note_fix_integral_float_as_integer) - << FixItHint::CreateReplacement(FL->getSourceRange(), LiteralValue); + S.Diag(FL->getExprLoc(), diag::warn_impcast_literal_float_to_integer) + << FL->getType() << T << FL->getSourceRange() << SourceRange(CContext); } std::string PrettyPrintInRange(const llvm::APSInt &Value, IntRange Range) { |