From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id D8678385842A; Mon, 28 Feb 2022 16:32:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8678385842A MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7412] c++: ICE with attribute on enumerator [PR104667] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 3f3246eb16f554c70c5ce87ad2c785f83adb4625 X-Git-Newrev: c8b0571e334792c0c789438617cfb7faf86ab599 Message-Id: <20220228163216.D8678385842A@sourceware.org> Date: Mon, 28 Feb 2022 16:32:16 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Feb 2022 16:32:17 -0000 https://gcc.gnu.org/g:c8b0571e334792c0c789438617cfb7faf86ab599 commit r12-7412-gc8b0571e334792c0c789438617cfb7faf86ab599 Author: Marek Polacek Date: Thu Feb 24 16:41:53 2022 -0500 c++: ICE with attribute on enumerator [PR104667] 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.) 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. Diff: --- gcc/cp/decl2.cc | 3 +++ gcc/testsuite/g++.dg/ext/attrib64.C | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 2e58419ea51..22edc2ba7f9 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -1298,6 +1298,9 @@ is_late_template_attribute (tree attr, tree decl) { tree type = TYPE_P (decl) ? decl : TREE_TYPE (decl); + if (!type) + return true; + /* We can't apply any attributes to a completely unknown type until instantiation time. */ enum tree_code code = TREE_CODE (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;