Is there any way to have gcc or g++ emit a warning when an implicit conversion within an if, something like if(25.0), is used?
This question is inspired by a bug I recently observed where a parenthesis was mis-placed, and the if statement has the unexpected behavior illustrated in the example below.
I understand from this discussion on the comma operator that this is valid (although ugly) code, but I would like to get a warning.
I tried -Wconversion -Wall -pedantic with g++ (GCC) 4.1.2 and g++ (GCC) 4.6.3 without any luck.
#include <cstdio>
bool passMin(float val, float minval=10.) {return minval<val;}
int main () {
float val(20.0), minval(25.0);
if(passMin(val), minval) printf(" pass (p( ), )"); else printf(" fail (p( ), )");
printf("\n");
if(passMin(val, minval)) printf(" pass (p( , ))"); else printf(" fail (p( , ))");
printf("\n");
}
This produces:
pass (p( ), )
fail (p( , ))