public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "aaron at aaronballman dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/108796] Can't intermix C2x and GNU style attributes
Date: Thu, 16 Feb 2023 20:06:15 +0000	[thread overview]
Message-ID: <bug-108796-4-UeCik8a2E7@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108796-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #9 from Aaron Ballman <aaron at aaronballman dot com> ---
> GNU attributes are declaration specifiers *in the previous examples given 
> here*, not necessarily in all other cases.

Thanks for clarifying!

> (There is then logic in GCC to handle __attribute__ that, according to the 
> syntax, should appertain to a particular entity, so that it's instead 
> applied to some other related entity; for example, moving an attribute 
> from a declaration to its type.  This is deliberately *not* done for [[]] 
> attribute syntax; those attributes are expected to be written in a correct 
> location for the entity they appertain to.)

This touches on why I came to the decision I did in Clang. What `__attribute__`
will apply to is sometimes inscrutable and users are (perhaps) used to it
sliding around to whatever works. As you point out, `[[]]` doesn't have the
same behavior; it has strict appertainment. Because `__attribute__` doesn't
have strict appertainment, it did not seem like an issue for it to continue to
shift around to whatever makes sense. Thus `[[]]` will apply to what the
standard says it applies to, and `__attribute__` applies to whatever it should
apply to based on the attribute names in the specifier, but users don't have to
know whether they need to write `[[]] __attribute__(())` vs `__attribute__(())
[[]]`. (Clang also supports `__declspec`, so there are more combinations to
worry about sometimes.)

It really boils down to whether `__attribute__` is fundamentally a different
"thing" than `[[]]` and I couldn't convince myself they were different. The
result is, when the grammar allows consecutive attribute syntaxes, we parse all
allowed syntaxes in a loop so users can write them in an arbitrary order.

  parent reply	other threads:[~2023-02-16 20:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15  3:07 [Bug c/108796] New: GCC 13 accepts [[noreturn]] attribute without -std=c2x sam at gentoo dot org
2023-02-15  3:10 ` [Bug c/108796] " sam at gentoo dot org
2023-02-15  3:11 ` sam at gentoo dot org
2023-02-15  3:44 ` sam at gentoo dot org
2023-02-15  3:46 ` pinskia at gcc dot gnu.org
2023-02-15  3:47 ` [Bug c/108796] Can't intermix C2x and GNU style attributes pinskia at gcc dot gnu.org
2023-02-15 21:02 ` joseph at codesourcery dot com
2023-02-16 13:14 ` aaron at aaronballman dot com
2023-02-16 19:20 ` joseph at codesourcery dot com
2023-02-16 20:06 ` aaron at aaronballman dot com [this message]
2023-02-16 22:34 ` aaron at aaronballman dot com
2024-01-14 10:26 ` pinskia at gcc dot gnu.org

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-108796-4-UeCik8a2E7@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).