From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 26CB8385B514; Thu, 16 Feb 2023 20:06:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26CB8385B514 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676577976; bh=3bRF3NhSVj7zIc4I2Wbb74S8178lI/OP6CJxSIE2MAs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pXtPjxaXLrm0BzO6tzfkhRGmWqpukzEOFmPp+aH1bdcJ4g6EKQjnIEOzUlduXO0AK JroewaSyAaoTGQB4vJDULTONLoJFwppNGUQ0YI57El3bPCH9KJRVbtaOBLs7t6HXNJ 3AjDalhkxG8Sm+L1Kx2tcSHBDeNH8zYhlzPdDFQ8= From: "aaron at aaronballman dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: aaron at aaronballman dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108796 --- Comment #9 from Aaron Ballman --- > GNU attributes are declaration specifiers *in the previous examples given= =20 > here*, not necessarily in all other cases. Thanks for clarifying! > (There is then logic in GCC to handle __attribute__ that, according to th= e=20 > syntax, should appertain to a particular entity, so that it's instead=20 > applied to some other related entity; for example, moving an attribute=20 > from a declaration to its type. This is deliberately *not* done for [[]]= =20 > attribute syntax; those attributes are expected to be written in a correc= t=20 > location for the entity they appertain to.) This touches on why I came to the decision I did in Clang. What `__attribut= e__` 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 sho= uld apply to based on the attribute names in the specifier, but users don't hav= e 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.=