Index: lib/Sema/SemaChecking.cpp =================================================================== --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -8625,6 +8625,9 @@ } static void AnalyzeImplicitConversions(Sema &S, Expr *E, SourceLocation CC); +static void CheckImplicitConversion(Sema &S, Expr *E, QualType T, + SourceLocation CC, + bool *ICContext = nullptr); static bool IsEnumConstOrFromMacro(Sema &S, Expr *E) { // Suppress cases where we are comparing against an enum constant. @@ -9164,6 +9167,13 @@ } AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc()); + + QualType RQType = E->getRHS()->getType(); + QualType LQType = E->getLHS()->getType(); + if ((RQType != LQType) && RQType->isRealFloatingType() && + LQType->isRealFloatingType()) + CheckImplicitConversion(S, E->getRHS()->IgnoreParenImpCasts(), + E->getLHS()->getType(), E->getOperatorLoc()); } /// Diagnose an implicit cast; purely a helper for CheckImplicitConversion. @@ -9501,9 +9511,8 @@ return true; } -static void -CheckImplicitConversion(Sema &S, Expr *E, QualType T, SourceLocation CC, - bool *ICContext = nullptr) { +static void CheckImplicitConversion(Sema &S, Expr *E, QualType T, + SourceLocation CC, bool *ICContext) { if (E->isTypeDependent() || E->isValueDependent()) return; const Type *Source = S.Context.getCanonicalType(E->getType()).getTypePtr(); @@ -9873,8 +9882,8 @@ if (BO->isComparisonOp()) return AnalyzeComparison(S, BO); - // And with simple assignments. - if (BO->getOpcode() == BO_Assign) + // And with assignments. + if (BO->isAssignmentOp()) return AnalyzeAssignment(S, BO); } Index: test/Sema/constant-conversion.c =================================================================== --- test/Sema/constant-conversion.c +++ test/Sema/constant-conversion.c @@ -73,7 +73,7 @@ f.twoBits1 = ~1; // no-warning f.twoBits2 = ~2; // expected-warning {{implicit truncation from 'int' to bit-field changes value from -3 to 1}} f.twoBits1 &= ~1; // no-warning - f.twoBits2 &= ~2; // no-warning + f.twoBits2 &= ~2; // expected-warning {{implicit truncation from 'int' to bit-field changes value from -3 to 1}} } void test8() { Index: test/Sema/conversion.c =================================================================== --- test/Sema/conversion.c +++ test/Sema/conversion.c @@ -436,7 +436,7 @@ } void double2float_test2(double a, float *b) { - *b += a; + *b += a; // expected-warning {{implicit conversion loses floating-point precision: 'double' to 'float'}} } float sinf (float x);