public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kkylheku at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/114526] ISO C does not prohibit extensions: fix misconception.
Date: Thu, 28 Mar 2024 22:33:05 +0000	[thread overview]
Message-ID: <bug-114526-4-UYTWSIw9Rf@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114526-4@http.gcc.gnu.org/bugzilla/>

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".

  parent reply	other threads:[~2024-03-28 22:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28 22:00 [Bug c/114526] New: " kkylheku at gmail dot com
2024-03-28 22:03 ` [Bug c/114526] " pinskia at gcc dot gnu.org
2024-03-28 22:06 ` pinskia at gcc dot gnu.org
2024-03-28 22:33 ` kkylheku at gmail dot com [this message]
2024-03-29  0:27 ` harald at gigawatt dot nl
2024-03-29  1:20 ` jsm28 at gcc dot gnu.org
2024-03-29  1:23 ` harald at gigawatt dot nl
2024-03-29  3:07 ` kkylheku at gmail dot com
2024-04-02 16:04 ` jsm28 at gcc dot gnu.org
2024-04-02 16:16 ` harald at gigawatt dot nl
2024-04-02 16:20 ` harald at gigawatt dot nl
2024-04-02 17:21 ` jsm28 at gcc dot gnu.org
2024-04-02 17:29 ` kkylheku at gmail dot com
2024-04-02 17:35 ` kkylheku at gmail dot com
2024-04-02 17:57 ` harald at gigawatt dot nl
2024-04-02 18:18 ` jsm28 at gcc dot gnu.org
2024-04-02 19:06 ` harald at gigawatt dot nl
2024-04-02 19:41 ` kkylheku at gmail dot com
2024-04-02 21:37 ` harald at gigawatt dot nl
2024-04-03  5:48 ` kkylheku at gmail dot com
2024-04-03  8:07 ` harald at gigawatt dot nl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114526-4-UYTWSIw9Rf@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).