[cfe-commits] [PATCH] Introduces a new warning for implicit conversions from floating point to bool

Nico Weber thakis at chromium.org
Mon Jun 11 08:18:26 PDT 2012


Hi Andreas,

Thanks for your patch.

Have you evaluated this warning on a large-ish codebase? How many bugs
did it find, how many false positives did it have?

As far as I understand, the philosophy for warnings is that they
should be good enough to be on by default (and be on by default), or
they shouldn't be in the tree.

Nico

On Mon, Jun 11, 2012 at 7:22 AM, Andreas Eckleder <aeckleder at google.com> wrote:
> Hello,
>
> I've just started working on clang and the following is hopefully
> going to be my first contribution to the project.
> The patch adds a diagnostic to detect implicit conversion from
> floating point to bool and output a warning.
>
> This diagnostic is can be turned on using
> -Wimplicit-conversion-floating-point-to-bool (off by-default).
> The patch contains a test case
> (test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp).
>
>
> Example:
> compile this code with -Wimplicit-conversion-floating-point-to-bool
>
> void bar() {
>
>  float f = 1.7;
>  bool b = f;   // expected-warning {{implicit conversion turns
> floating-point number into bool: 'float' to 'bool'}}
>
>  double d = 1.7;
>  b = d;        // expected-warning {{implicit conversion turns
> floating-point number into bool: 'double' to 'bool'}}
>
> }
>
> Compiler will emit a warning as follows:
>
> warn-implicit-conversion-floating-point-to-bool.cpp:6:12: warning:
> implicit conversion turns floating-point number into
>      bool: 'float' to 'bool' [-Wimplicit-conversion-floating-point-to-bool]
>  bool b = f;   // expected-warning {{implicit conversion turns
> floating-point number into bool: 'float' to 'bool'}}
>       ~   ^
> warn-implicit-conversion-floating-point-to-bool.cpp:9:7: warning:
> implicit conversion turns floating-point number into bool:
>      'double' to 'bool' [-Wimplicit-conversion-floating-point-to-bool]
>  b = d;        // expected-warning {{implicit conversion turns
> floating-point number into bool: 'double' to 'bool'}}
>    ~ ^
> 2 warnings generated.
>
> Please, review this patch.
> Thanks!
>
> Andreas
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list