public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-9629] c++: ICE with attribute on enumerator [PR104667]
Date: Mon, 28 Feb 2022 16:35:14 +0000 (GMT)	[thread overview]
Message-ID: <20220228163514.D56BD3858C60@sourceware.org> (raw)

https://gcc.gnu.org/g:89cea574209521204c8cfe6c4f8c5760581a306c

commit r11-9629-g89cea574209521204c8cfe6c4f8c5760581a306c
Author: Marek Polacek <polacek@redhat.com>
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.c (is_late_template_attribute): Cope with a decl without
            a type.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/ext/attrib64.C: New test.
    
    (cherry picked from commit c8b0571e334792c0c789438617cfb7faf86ab599)

Diff:
---
 gcc/cp/decl2.c                      |  3 +++
 gcc/testsuite/g++.dg/ext/attrib64.C | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index aaeda8220f7..941c777da9d 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1202,6 +1202,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<typename> struct A {
+  enum E { // { dg-warning "only applies to function types" }
+    e __attribute__ ((access(read_only))),
+    f __attribute__ ((deprecated))
+  };
+};
+
+A<int> a;


                 reply	other threads:[~2022-02-28 16:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220228163514.D56BD3858C60@sourceware.org \
    --to=mpolacek@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).