g++ 2.96 -W issues bogus warning for conditional expression with enum and unsigned

Martin Sebor sebor@roguewave.com
Tue Jul 4 21:59:00 GMT 2000


Hi,

the program below issues a warning when compiled with gcc -W. This new
warning (it was not present in 2.95.2) disappears if the type of the
third subexpression is int.

I don't see a reason for the warning in 5.16, p6. In particular, bullet
2 says: "The second and third operands have arithmetic or enumeration
type; the usual arithmetic conversions are performed to bring them to a
common type, and the result is of that type." The usual arithmetic
conversion would in this case be a conversion to unsigned int according
to 4.5, p2. Am I missing something?

Thanks
Martin

PS Also, the text of the warning is unnecessarily broken up into two
lines.


$ gcc -W t.cpp 
t.cpp: In function `int main (int)':
t.cpp:5: warning: enumeral and non-enumeral type in conditional
expression


$ cat t.cpp

int main ()
{
    enum { e };

    return e ? e : 0U;
}


More information about the Gcc-bugs mailing list