From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 2FE673858D28 for ; Fri, 25 Feb 2022 21:59:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2FE673858D28 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-311-Nf7c1rc4OsebALF-zKFd5Q-1; Fri, 25 Feb 2022 16:59:16 -0500 X-MC-Unique: Nf7c1rc4OsebALF-zKFd5Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F17AD51DC for ; Fri, 25 Feb 2022 21:59:15 +0000 (UTC) Received: from pdp-11.hsd1.ma.comcast.net (unknown [10.22.34.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9281983894; Fri, 25 Feb 2022 21:59:15 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with attribute on enumerator [PR104667] Date: Fri, 25 Feb 2022 16:59:08 -0500 Message-Id: <20220225215908.324041-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Fri, 25 Feb 2022 21:59:22 -0000 When processing a template, the enumerators we build don't have a type yet. But is_late_template_attribute is not prepared to see a _DECL without a type, so we crash on enum tree_code code = TREE_CODE (type); (I found that we don't give the "is deprecated" warning for the enumerator 'f' in the test. Reported as PR104682.) Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11? PR c++/104667 gcc/cp/ChangeLog: * decl2.cc (is_late_template_attribute): Cope with a decl without a type. gcc/testsuite/ChangeLog: * g++.dg/ext/attrib64.C: New test. --- gcc/cp/decl2.cc | 2 +- gcc/testsuite/g++.dg/ext/attrib64.C | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/attrib64.C diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 2e58419ea51..dc7710660d0 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -1300,7 +1300,7 @@ is_late_template_attribute (tree attr, tree decl) /* We can't apply any attributes to a completely unknown type until instantiation time. */ - enum tree_code code = TREE_CODE (type); + enum tree_code code = type ? TREE_CODE (type) : ERROR_MARK; if (code == TEMPLATE_TYPE_PARM || code == BOUND_TEMPLATE_TEMPLATE_PARM || code == TYPENAME_TYPE) diff --git a/gcc/testsuite/g++.dg/ext/attrib64.C b/gcc/testsuite/g++.dg/ext/attrib64.C new file mode 100644 index 00000000000..4a4505fc4b2 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attrib64.C @@ -0,0 +1,11 @@ +// PR c++/104667 +// { dg-do compile } + +template struct A { + enum E { // { dg-warning "only applies to function types" } + e __attribute__ ((access(read_only))), + f __attribute__ ((deprecated)) + }; +}; + +A a; base-commit: ae3c4e521dd0b66db712639298cd08331d62f315 -- 2.35.1