views:

92

answers:

2

I was just curious if the following code should result in warning or not by g++ compiler:

// Snip #1
bool x = 0;
x++;

// Snip #2
switch (x) {
default:
    printf("hi\n");
}

The problem is such statements exist in a legacy code i work upon :-|, I guess there should be some warnings for these?

I have g++-4.4.3c

A: 

With gcc, -Wall does not actually turn on all warnings. The man page will cover all your options, but to be really thorough, use "-Wall -Weff-c++ -pedantic -Werror".

smithco
A: 

Incrementing a bool is a deprecated function, yet it is still valid and achieves the desired result, therefore a warning should not appear, it is just bad practice to do so.

njak32