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

--- Comment #3 from Kaz Kylheku <kkylheku at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> Actually it is a required diagnostic. See PR 11234 for explanation on how.
> This was changed a little over 20 years ago explictly to reject this because
> it is invalid C.
> 
> *** This bug has been marked as a duplicate of bug 11234 ***

This bug report is more than about the specific warning about conversion of
function and object pointers.

It's about all/any options that don't belong in -pedantic; and about false
sentences in diagnostics and documentation.

Now, a conversion between a function and object pointer requires no diagnostic
if the required cast is present. Either way, it is undefined behavior.

I'm referencing the N3220 draft.

The 6.3 Conversions sections lists, in 6.3.2.3 Pointers, various possible
conversions among pointers. Conversions between pointers to object types and to
function types are not mentioned.

It has always been like that going back to ISO C 90 and ANSI C.

As an extension, not only is it not forbidden, but it is listed in an Appendix
as a common extension. In the N3220 draft we have:

  J.5.8 Function pointer casts

  A pointer to an object or to void may be cast to a pointer to a function,
  allowing data to be invoked as a function (6.5.5).

A diagnostic is required if a pointer to function is converted to an object
pointer, without a cast.

  6.5.5 Cast Operators

  Constraints

  ...

  Conversions that involve pointers, other than where permitted by the
  constraints of 6.5.17.2, shall be specified by means of an explicit cast.  

If a cast is present, the constraint is satisfied; the conversion is no longer
implicit but explicit. No other constraints apply to the conversion. In fact no
other requirements at all, since it is not defined.

GCC provides the common extension described in J.5.8. It is conforming; nothing
needs to be diagnosed about a program which uses it. It, and other extensions,
must not be called "forbidden".

Reply via email to