[Bug c/51294] spurious warning from -Wconversion in C and C++ in conditional expressions

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 24 19:09:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51294

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-11-24 18:37:31 UTC ---
(In reply to comment #4)
> Shouldn't integral conversion rules apply if the types of the second and third
> arguments to a conditional expression differ.

Yes.

> So zero should be converted from the default int to a char

No, the char is converted to int.  Hence the warning.

> as presumably the
> older version of gcc did. 

Nope.

> Perhaps a language lawyer could explain why this is or isn't a bug.

I did ;)

> Though obviously warnings are not covered by the standard.
> 
> 
> Note:
> 
> (haveBar?bar_:(char)0)
> 
> is not an acceptable workaround for C++ if -Wold-style-cast is used (which is
> in my experience typical). It would have to be
> 
> (haveBar?bar_:static_cast<char>(0))
> 
> which is a notch higher in annoyingness.

OK then:

  (haveBar?bar_:char())



More information about the Gcc-bugs mailing list