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
0001-Introduces-a-new-warning-for-implicit-conversions-fr.patch
Description: Binary data
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
