From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp1.lauterbach.com (smtp1.lauterbach.com [62.154.241.196]) by sourceware.org (Postfix) with ESMTPS id 50B62383541E for ; Tue, 18 May 2021 17:35:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 50B62383541E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lauterbach.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=franz.sirl-kernel@lauterbach.com Received: (qmail 25299 invoked by uid 484); 18 May 2021 17:35:52 -0000 X-Qmail-Scanner-Diagnostics: from dslb-084-061-153-110.084.061.pools.vodafone-ip.de by smtp1.lauterbach.com (envelope-from , uid 484) with qmail-scanner-2.11 (mhr: 1.0. clamdscan: 0.99/21437. spamassassin: 3.4.0. Clear:RC:1(84.61.153.110):. Processed in 0.063371 secs); 18 May 2021 17:35:52 -0000 Received: from dslb-084-061-153-110.084.061.pools.vodafone-ip.de (HELO [192.168.178.20]) (Authenticated_SSL:fsirl@[84.61.153.110]) (envelope-sender ) by smtp1.lauterbach.com (qmail-ldap-1.03) with TLS_AES_256_GCM_SHA384 encrypted SMTP for ; 18 May 2021 17:35:51 -0000 Subject: Re: [PATCH v2] c++: Check attributes on friend declarations [PR99032] To: Marek Polacek , Jason Merrill Cc: GCC Patches References: <20210512024503.398582-1-polacek@redhat.com> <54dfab57-27f6-793f-0ae6-5d72c0faf531@redhat.com> <38e5679b-4967-26a7-5110-1f17e5c51ef0@redhat.com> From: Franz Sirl Message-ID: Date: Tue, 18 May 2021 19:35:52 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 May 2021 17:35:58 -0000 Am 2021-05-14 um 00:08 schrieb Marek Polacek via Gcc-patches: > On Wed, May 12, 2021 at 08:27:18PM -0400, Jason Merrill wrote: >> On 5/12/21 8:03 PM, Marek Polacek wrote: >>> diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c >>> index 89f874a32cc..2bcefb619aa 100644 >>> --- a/gcc/cp/decl2.c >>> +++ b/gcc/cp/decl2.c >>> @@ -1331,6 +1331,20 @@ any_dependent_type_attributes_p (tree attrs) >>> return false; >>> } >>> +/* True if ATTRS contains any attribute that requires a type. */ >> >> Let's invert this to check if ATTRS contains any attribute that does *not* >> require a type, and would therefore apply to the decl. > > Sounds good, done. Now I don't need to check *attrlist. > I've also fixed up the xfail thing in my new test. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > -- >8 -- > This patch implements [dcl.attr.grammar]/5: "If an attribute-specifier-seq > appertains to a friend declaration ([class.friend]), that declaration shall > be a definition." > > This restriction applies to C++11-style attributes as well as GNU > attributes with the exception that we allow GNU attributes that require > a type, such as vector_size to continue accepting code as in attrib63.C. > There are various forms of friend declarations, we have friend > templates, C++11 extended friend declarations, and so on. In some cases > we already ignore the attribute and warn that it was ignored. But > certain cases weren't diagnosed, and with this patch we'll give a hard > error. I tried hard not to emit both a warning and error and I think it > worked out. > > Jason provided the cp_parser_decl_specifier_seq hunk to detect using > standard attributes in the middle of decl-specifiers, which is invalid. > > Co-authored-by: Jason Merrill > > gcc/cp/ChangeLog: > > PR c++/99032 > * cp-tree.h (any_non_type_attribute_p): Declare. > * decl.c (grokdeclarator): Diagnose when an attribute appertains to > a friend declaration that is not a definition. > * decl2.c (any_non_type_attribute_p): New. > * parser.c (cp_parser_decl_specifier_seq): Diagnose standard attributes > in the middle of decl-specifiers. > (cp_parser_elaborated_type_specifier): Diagnose when an attribute > appertains to a friend declaration that is not a definition. > (cp_parser_member_declaration): Likewise. > Hi, I haven't investigated it in detail yet, but it seems this change breaks building Qt-based (tested with Qt-5.12.7) applications. Sample error output with trunk@r12+876 -std=gnu++14: /usr/include/qt5/QtCore/qvariant.h:470:33: error: attribute appertains to a friend declaration that is not a definition friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant &); ^~~~~~~~ For GCC Q_CORE_EXPORT is defined (via Q_DECL_EXPORT) to __attribute__((visibility("default"))) AFAICS. As this error seemingly cannot be turned into a warning, it's probably quite a problem for many people. regards, Franz