https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99317

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
         Resolution|---                         |WONTFIX
             Status|UNCONFIRMED                 |RESOLVED
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=44209

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
To expand on Andrew's comment: The C rules specify the type of the result of
operator ?: when either of the second and third operands is a pointer to void,
but they do no specify the result type when the operands are pointers to
incompatible types (like int* and float*).  The warning points out the latter.

The C++ rules, OTOH, are more restrictive and make the ?: expression valid only
when the types of the arguments can be implicitly converted to one another. 
Since in C++ a pointer to void isn't implicitly convertible to a pointer to an
object type all the expressions in the test case are invalid.

In C mode, the -Wc++-compat option helps detect C/C++ incompatibilities and
detects this problem (below).  So with that, since the problem is diagnosed
under the right option, I think this report can be resolved as WONTFIX.  (That
the warning in comment #0 is issued unconditionally and not under the control
of a specific option, is a separate problem tracked in in bug 44209.)

$ gcc -S -Wall -Wc++-compat pr99317.c
pr99317.c: In function ‘foo’:
pr99317.c:3:17: warning: request for implicit conversion from ‘void *’ to
‘float *’ not permitted in C++ [-Wc++-compat]
    3 |     float * f = v;
      |                 ^
pr99317.c:4:15: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
    4 |     int * i = w;
      |               ^
pr99317.c:5:19: warning: pointer type mismatch in conditional expression
    5 |     return (x ? f : i);
      |                   ^
pr99317.c:5:19: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
    5 |     return (x ? f : i);
      |            ~~~~~~~^~~~
pr99317.c: In function ‘foo1’:
pr99317.c:10:17: warning: request for implicit conversion from ‘void *’ to
‘float *’ not permitted in C++ [-Wc++-compat]
   10 |     float * f = v;
      |                 ^
pr99317.c:11:15: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
   11 |     int * i = w;
      |               ^
pr99317.c:12:19: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
   12 |     return (1 ? f : (void *)i);
      |            ~~~~~~~^~~~~~~~~~~~
pr99317.c: In function ‘bar’:
pr99317.c:16:17: warning: request for implicit conversion from ‘void *’ to
‘float *’ not permitted in C++ [-Wc++-compat]
   16 |     float * f = v;
      |                 ^
pr99317.c:17:15: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
   17 |     int * i = w;
      |               ^
pr99317.c:18:19: warning: request for implicit conversion from ‘void *’ to ‘int
*’ not permitted in C++ [-Wc++-compat]
   18 |     return (x ? f : (void *)i);
      |            ~~~~~~~^~~~~~~~~~~~

Reply via email to