From: Richard Trieu Date: Fri, 22 Apr 2016 22:14:32 +0000 (+0000) Subject: Revert the bool portion of r267054 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=beccaa284d84f331d5d76f8e509c3ee1545584fb;p=clang Revert the bool portion of r267054 Remove the floating point to bool conversion warnings. Some of these conversions will be caught by -Wliteral-conversion and -Wfloat-conversion git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267234 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 487308293a..8b5d8df6fc 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -49,12 +49,8 @@ def EnumConversion : DiagGroup<"enum-conversion">; def FloatOverflowConversion : DiagGroup<"float-overflow-conversion">; def FloatZeroConversion : DiagGroup<"float-zero-conversion">; -def FloatBoolConstantConversion : DiagGroup<"float-bool-constant-conversion">; -def FloatBoolConversion : - DiagGroup<"float-bool-conversion", [FloatBoolConstantConversion]>; def FloatConversion : - DiagGroup<"float-conversion", [FloatBoolConversion, - FloatOverflowConversion, + DiagGroup<"float-conversion", [FloatOverflowConversion, FloatZeroConversion]>; def DoublePromotion : DiagGroup<"double-promotion">; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 355892062b..053dca3de8 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2768,13 +2768,6 @@ def warn_impcast_float_integer : Warning< "implicit conversion turns floating-point number into integer: %0 to %1">, InGroup, DefaultIgnore; -def warn_impcast_float_bool : Warning< - "implicit conversion turns floating-point number into boolean: %0 to %1">, - InGroup, DefaultIgnore; -def warn_impcast_float_to_bool : Warning< - "implicit conversion from %0 to %1 changes value from %2 to %3">, - InGroup; - def warn_impcast_float_to_integer : Warning< "implicit conversion of out of range value from %0 to %1 changes value " "from %2 to %3">, diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 0592a83011..fb11adb451 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -7403,13 +7403,8 @@ void DiagnoseFloatingImpCast(Sema &S, Expr *E, QualType T, bool IsConstant = E->EvaluateAsFloat(Value, S.Context, Expr::SE_AllowSideEffects); if (!IsConstant) { - if (IsBool) { - return DiagnoseImpCast(S, E, T, CContext, diag::warn_impcast_float_bool, - PruneWarnings); - } else { - return DiagnoseImpCast(S, E, T, CContext, - diag::warn_impcast_float_integer, PruneWarnings); - } + return DiagnoseImpCast(S, E, T, CContext, + diag::warn_impcast_float_integer, PruneWarnings); } bool isExact = false; @@ -7418,17 +7413,14 @@ void DiagnoseFloatingImpCast(Sema &S, Expr *E, QualType T, T->hasUnsignedIntegerRepresentation()); if (Value.convertToInteger(IntegerValue, llvm::APFloat::rmTowardZero, &isExact) == llvm::APFloat::opOK && - isExact && !IsBool) { + isExact) { if (IsLiteral) return; return DiagnoseImpCast(S, E, T, CContext, diag::warn_impcast_float_integer, PruneWarnings); } unsigned DiagID = 0; - if (IsBool) { - // Warn on all floating point to bool conversions - DiagID = diag::warn_impcast_float_to_bool; - } else if (IsLiteral) { + if (IsLiteral) { // Warn on floating point literal to integer. DiagID = diag::warn_impcast_literal_float_to_integer; } else if (IntegerValue == 0) { diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp index 022b3111b6..48c5b23207 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp @@ -58,8 +58,8 @@ void float_to_int() { Agg ce1 = { Convert(1.0) }; // expected-error {{type 'float' cannot be narrowed to 'char'}} expected-note {{silence}} Agg ce2 = { ConvertVar() }; // expected-error {{type 'double' cannot be narrowed to 'char'}} expected-note {{silence}} - bool b{1.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}} expected-warning {{changes value}} - Agg ab = {0.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}} expected-warning {{changes value}} + bool b{1.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}} + Agg ab = {0.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}} } // * from long double to double or float, or from double to float, except where diff --git a/test/SemaCXX/warn-float-conversion.cpp b/test/SemaCXX/warn-float-conversion.cpp index 5a5532572a..fc221893ae 100644 --- a/test/SemaCXX/warn-float-conversion.cpp +++ b/test/SemaCXX/warn-float-conversion.cpp @@ -1,8 +1,6 @@ // RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-literal-conversion -Wfloat-conversion -DFLOAT_CONVERSION -DZERO -DBOOL -DCONSTANT_BOOL -DOVERFLOW // RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-conversion -Wfloat-overflow-conversion -DOVERFLOW // RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-conversion -Wfloat-zero-conversion -DZERO -// RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-conversion -Wfloat-bool-constant-conversion -DCONSTANT_BOOL -// RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-pc-linux-gnu %s -Wno-conversion -Wfloat-bool-conversion -DCONSTANT_BOOL -DBOOL float ReturnFloat(); @@ -68,37 +66,6 @@ void TestConstantFloat() { } #endif // FLOAT_CONVERSION -#ifdef CONSTANT_BOOL -const float pi = 3.1415; - -void TestConstantBool() { - bool b1 = 0.99f; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 0.99 to true}} - bool b2 = 0.99; // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 0.99 to true}} - bool b3 = 0.0f; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 0 to false}} - bool b4 = 0.0; // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 0 to false}} - bool b5 = 1.0f; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 1 to true}} - bool b6 = 1.0; // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 1 to true}} - bool b7 = pi; // expected-warning {{implicit conversion from 'const float' to 'bool' changes value from 3.1415 to true}} - bool b8 = pi - pi; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 0 to false}} -} -#endif // CONSTANT_BOOL - -#ifdef BOOL -const float E = 2.718; - -float GetFloat(); -double GetDouble(); - -void TestBool() { - bool b1 = GetFloat(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'float' to 'bool'}} - bool b2 = GetDouble(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'double' to 'bool'}} - bool b3 = 0.0 * GetDouble(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'double' to 'bool'}} - bool b4 = GetFloat() + GetDouble(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'double' to 'bool'}} - bool b5 = E + GetFloat(); // expected-warning {{implicit conversion turns floating-point number into boolean: 'float' to 'bool'}} -} - -#endif // BOOL - #ifdef ZERO void TestZero() { const float half = .5; diff --git a/test/SemaCXX/warn-literal-conversion.cpp b/test/SemaCXX/warn-literal-conversion.cpp index 8a74166a01..875aa1dec5 100644 --- a/test/SemaCXX/warn-literal-conversion.cpp +++ b/test/SemaCXX/warn-literal-conversion.cpp @@ -38,3 +38,14 @@ void test0() { int y = (24*60*60) * 0.25; int pennies = 123.45 * 100; } + +// Similarly, test floating point conversion to bool. Only float values of zero +// are converted to false; everything else is converted to true. +void test1() { + bool b1 = 0.99f; // expected-warning {{implicit conversion from 'float' to 'bool' changes value from 0.99 to true}} + bool b2 = 0.99; // expected-warning {{implicit conversion from 'double' to 'bool' changes value from 0.99 to true}} + // These do not warn because they can be directly converted to integral + // values. + bool b3 = 0.0f; + bool b4 = 0.0; +}