forked from OSchip/llvm-project
Extend -Wliteral-conversion to catch "int i = -1.234"
llvm-svn: 139326
This commit is contained in:
parent
460be996ce
commit
042ce8e9d8
|
@ -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 {
|
||||
|
|
|
@ -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.)
|
||||
|
|
Loading…
Reference in New Issue