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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |manu at gcc dot gnu.org
            Summary|spurious warning from       |spurious warning from
                   |-Wconversion in C and C++   |-Wconversion in C and C++
                   |                            |in conditional expressions

--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-11-24 
15:46:16 UTC ---
(In reply to comment #2)
> (In reply to comment #0)
> > 0 is a const so the compiler should be able to choose the correct type.
> 
> 0 is an int, so the compiler is required by the standard to make the
> conditional expression (haveBar?bar_:0) have type int.
> 
> It shouldn't warn though, as the conversion from int to char won't alter the
> value.

This was implemented in this patch:

http://gcc.gnu.org/ml/gcc-patches/2009-08/msg00582.html

which was rejected. Perhaps a cut-down version that addresses only this issue
would be accepted. But perhaps no. Feel free to take it.

BTW, clang does not warn for this case, while it does if bar_ is an int:

pr51294.c:3:23: warning: implicit conversion loses integer precision: 'int' to
'char' [-Wconversion]
  char zuul = haveBar?bar_:0;
                     ~^~~~
1 warning generated.

It also points to the correct location of the issue, whereas GCC doesn't.

Reply via email to