From patchwork Tue Sep 3 22:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1980314 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=akk0kWAL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wz01Y4Ws7z1yg3 for ; Wed, 4 Sep 2024 08:00:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DFF1F3861034 for ; Tue, 3 Sep 2024 22:00:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id C270C385B50D for ; Tue, 3 Sep 2024 22:00:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C270C385B50D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C270C385B50D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725400826; cv=none; b=gfqkTZlsEmaEeA30bY0mGLoM8Ae3JugdQh/HGj0J5ki6jbtaJ8dj1p+5yA/EDYfg66HIHR17lUbCdA7gxpA8+vR1XtherhDGpybvkHONvLGqylguY7tttoDjYVCXzhJzWA+FrXz4Ub5MPPHTHMCyBSF/svQFnRZ0IYX1r7d0/98= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725400826; c=relaxed/simple; bh=8DEQHQnZJFr1teQRTeWzqi4mxS3xOJVloK8jr2JwE24=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BQpJDYFUpUVUKsuRGzj72mZ2lPvWyQwbylowNQUWr9dvhdK6bKefgfxQBezCDArS9kMzB6xsv7mzCnOucegqHSkV68kyPT5SDfQn16yBdby/tNbL1sJvKvLeTmXi7ppGH6PuinzNRyDjRSHtcwmzoTn4tAJwPWMnCAsaszc/JRs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725400824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hqc75/MDSJ8vAsMK9PT5x+F1NSv/hwFPwFIwd+JWnCI=; b=akk0kWALA4mF3zaqRJwM7tNedsiJyDG7UVGU3oZwOqK706NJhhFpobFwUKEaX1ju9i+b4A pa8HkbG5XG7/TZtbajarE+UzbQvh5x9y+l17UIcz6QZGCCQj+TDE/Fy00H93oqYtHay6XK XxclGjYZLX/bwirTFJrKUMWiZajA7gw= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-dKFxoFTCP4S9kS1NmwGkiw-1; Tue, 03 Sep 2024 18:00:22 -0400 X-MC-Unique: dKFxoFTCP4S9kS1NmwGkiw-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7a1d06f8f03so656073285a.1 for ; Tue, 03 Sep 2024 15:00:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725400821; x=1726005621; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hqc75/MDSJ8vAsMK9PT5x+F1NSv/hwFPwFIwd+JWnCI=; b=TPLCXM28kCXhzOGhd2qg5zIM6YY+JjpDA3X4GgAgjheTbAzZ7pmzRbIq/LqeTDS1DR d64Oar8N4afl0P0I8vPsXUKMJKkQYs2MhYyVHZLjGc8uWyguuefZRGoQQer3SY77Ireg +EuUnt/o6lZF2sdy9FwR39f9ndXLN8gFJiqAQUac2iHXBDkVSg3NjA5cATsedvwMnGsA FKMKDsJ9WcXRR9V9v7S3UImlNbwt1PyrydtEW5+t3PdUnMfDpxA+lCqxYJC4AUM0oUO4 k1+b3lllUjn2mOBS4cv3+QjN9i84gE1Jd/EG2LLcfuJxJ3In1zFgML+JfQRNwQ8ERZqt 6g+g== X-Gm-Message-State: AOJu0Ywy+TLa4E4DupcUKs5EAeidea6EqoZAjppZqkqm8tVqVIleA4sd KyFVahjlB6wBRWFBOd0dtokghiZMBfOuduC0vFxh2IcTc/8xp3WpRZ90k+Fa5nycuRuJ27WqW1K ATk/drPRaR/9vEOuHMQkKJfGd4l5BYKmAZu2rtWPrRGlyMQdFfzG+9gF7K/BejFeFnKofNbfUJe bdhFw7qUx4amrGsHJpkGpDrGRtyF6Q7cnkm6A= X-Received: by 2002:a05:620a:190d:b0:7a6:4a55:a5d8 with SMTP id af79cd13be357-7a89324afbbmr1439497185a.38.1725400821210; Tue, 03 Sep 2024 15:00:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGd5AfYXb6VvUNUY9hUekESOr2XNhV6RcA6wH9b3pGCcPBu0Q353/AKdqJAFh5IFNOt2Uqeiw== X-Received: by 2002:a05:620a:190d:b0:7a6:4a55:a5d8 with SMTP id af79cd13be357-7a89324afbbmr1439491185a.38.1725400820325; Tue, 03 Sep 2024 15:00:20 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a806bfc1a2sm570366785a.10.2024.09.03.15.00.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 15:00:19 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: support C++11 attributes in C++98 Date: Tue, 3 Sep 2024 18:00:08 -0400 Message-ID: <20240903220018.2785461-1-jason@redhat.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- I don't see any reason why we can't allow the [[]] attribute syntax in C++98 mode with a pedwarn just like many other C++11 features. In fact, we already do support it in some places in the grammar, but not in places that check cp_nth_tokens_can_be_std_attribute_p. Let's also follow the C front-end's lead in only warning about them when -pedantic. It still isn't necessary for this function to guard against Objective-C message passing syntax; we handle that with tentative parsing in cp_parser_statement, and we don't call this function in that context anyway. gcc/cp/ChangeLog: * parser.cc (cp_nth_tokens_can_be_std_attribute_p): Don't check cxx_dialect. * error.cc (maybe_warn_cpp0x): Only complain about C++11 attributes if pedantic. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/gen-attrs-1.C: Also run in C++98 mode. * g++.dg/cpp0x/gen-attrs-11.C: Likewise. * g++.dg/cpp0x/gen-attrs-13.C: Likewise. * g++.dg/cpp0x/gen-attrs-15.C: Likewise. * g++.dg/cpp0x/gen-attrs-75.C: Don't expect C++98 warning after __extension__. --- gcc/cp/error.cc | 7 ++++--- gcc/cp/parser.cc | 9 ++++----- gcc/testsuite/g++.dg/cpp0x/gen-attrs-1.C | 2 +- gcc/testsuite/g++.dg/cpp0x/gen-attrs-11.C | 2 +- gcc/testsuite/g++.dg/cpp0x/gen-attrs-13.C | 2 +- gcc/testsuite/g++.dg/cpp0x/gen-attrs-15.C | 2 +- gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C | 10 +++++----- 7 files changed, 17 insertions(+), 17 deletions(-) base-commit: 1fad396dd467326251572811b703e788e62a2588 diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 57cd76caf49..4a9e9aa3cdc 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -4735,9 +4735,10 @@ maybe_warn_cpp0x (cpp0x_warn_str str, location_t loc/*=input_location*/) "only available with %<-std=c++11%> or %<-std=gnu++11%>"); break; case CPP0X_ATTRIBUTES: - pedwarn (loc, OPT_Wc__11_extensions, - "C++11 attributes " - "only available with %<-std=c++11%> or %<-std=gnu++11%>"); + if (pedantic) + pedwarn (loc, OPT_Wc__11_extensions, + "C++11 attributes " + "only available with %<-std=c++11%> or %<-std=gnu++11%>"); break; case CPP0X_REF_QUALIFIER: pedwarn (loc, OPT_Wc__11_extensions, diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index edfa5a49440..64122d937fa 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -29924,11 +29924,10 @@ cp_nth_tokens_can_be_std_attribute_p (cp_parser *parser, size_t n) { cp_token *token = cp_lexer_peek_nth_token (parser->lexer, n); - return (cxx_dialect >= cxx11 - && ((token->type == CPP_KEYWORD && token->keyword == RID_ALIGNAS) - || (token->type == CPP_OPEN_SQUARE - && (token = cp_lexer_peek_nth_token (parser->lexer, n + 1)) - && token->type == CPP_OPEN_SQUARE))); + return ((token->type == CPP_KEYWORD && token->keyword == RID_ALIGNAS) + || (token->type == CPP_OPEN_SQUARE + && (token = cp_lexer_peek_nth_token (parser->lexer, n + 1)) + && token->type == CPP_OPEN_SQUARE)); } /* Return TRUE iff the next Nth tokens in the stream are possibly the diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-1.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-1.C index c2cf912047e..b1625d96916 100644 --- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-1.C +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-1.C @@ -1,3 +1,3 @@ -// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wno-c++11-extensions" } int **** [[gnu::format(printf, 1, 2)]] foo(const char *, ...); // { dg-warning "only applies to function types" } diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-11.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-11.C index 504b4565679..040f15c9dbb 100644 --- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-11.C +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-11.C @@ -1,4 +1,4 @@ -// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wno-c++11-extensions" } // PR c++/13791 template struct O { diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-13.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-13.C index a1b4a84b7e5..8997b845dfd 100644 --- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-13.C +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-13.C @@ -1,4 +1,4 @@ -// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wno-c++11-extensions" } // PR c++/13854 extern char *rindex [[gnu::__pure__]] (__const char *__s, int __c) throw (); diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-15.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-15.C index bf05dbeb31b..8b552ca1fbe 100644 --- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-15.C +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-15.C @@ -1,4 +1,4 @@ -// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wno-c++11-extensions" } // PR c++/15317 struct A diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C index bac80aa02ff..c2a328c7c7f 100644 --- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C @@ -1,6 +1,6 @@ // PR c++/101582 // { dg-do compile } -// { dg-options "" } +// { dg-options "-pedantic -Wno-extra-semi" } ; [[]] [[]] [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } } @@ -12,9 +12,9 @@ extern "C" [[]]; // { dg-warning "attributes only available with" "" { target c+ extern "C" extern "C" ; extern "C" extern "C" [[]][[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } } __extension__ ; -__extension__ [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } } +__extension__ [[]]; __extension__ __extension__ ; -__extension__ __extension__ [[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } } +__extension__ __extension__ [[]][[]]; namespace N { @@ -28,8 +28,8 @@ extern "C" [[]]; // { dg-warning "attributes only available with" "" { target c+ extern "C" extern "C" ; extern "C" extern "C" [[]][[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } } __extension__ ; -__extension__ [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } } +__extension__ [[]]; __extension__ __extension__ ; -__extension__ __extension__ [[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } } +__extension__ __extension__ [[]][[]]; }