[cfe-commits] [PATCH] Introduces a new warning for implicit conversions from floating point to bool
Andreas Eckleder
aeckleder at google.com
Mon Jun 11 07:22:02 PDT 2012
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Introduces-a-new-warning-for-implicit-conversions-fr.patch
Type: application/octet-stream
Size: 3325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120611/e28be1eb/attachment.obj>
More information about the cfe-commits
mailing list