public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6904] c++: dependent and non-dependent attributes [PR104245]
Date: Thu, 27 Jan 2022 21:55:48 +0000 (GMT)	[thread overview]
Message-ID: <20220127215548.08D503858430@sourceware.org> (raw)

https://gcc.gnu.org/g:66b86171188dcb61d2d0e0a4a98a7467e58a84a7

commit r12-6904-g66b86171188dcb61d2d0e0a4a98a7467e58a84a7
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jan 27 16:12:18 2022 -0500

    c++: dependent and non-dependent attributes [PR104245]
    
    A flaw in my patch for PR51344 was that cplus_decl_attributes calls
    decl_attributes after save_template_attributes, which messes up the ordering
    that save_template_attributes set up.  Fixed by splitting
    save_template_attributes around the call to decl_attributes.
    
            PR c++/104245
            PR c++/51344
    
    gcc/cp/ChangeLog:
    
            * decl2.cc (save_template_attributes): Take late attrs as parm.
            (cplus_decl_attributes): Call it after decl_attributes,
            splice_template_attributes before.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/lto/alignas1_0.C: New test.

Diff:
---
 gcc/cp/decl2.cc                       | 17 ++++++++---------
 gcc/testsuite/g++.dg/lto/alignas1_0.C |  7 +++++++
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index b68cf96fa81..a2aa5f1de4e 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -1352,18 +1352,14 @@ splice_template_attributes (tree *attr_p, tree decl)
   return late_attrs;
 }
 
-/* Remove any late attributes from the list in ATTR_P and attach them to
-   DECL_P.  */
+/* Attach any LATE_ATTRS to DECL_P, after the non-dependent attributes have
+   been applied by a previous call to decl_attributes.  */
 
 static void
-save_template_attributes (tree *attr_p, tree *decl_p, int flags)
+save_template_attributes (tree late_attrs, tree *decl_p, int flags)
 {
   tree *q;
 
-  if (attr_p && *attr_p == error_mark_node)
-    return;
-
-  tree late_attrs = splice_template_attributes (attr_p, *decl_p);
   if (!late_attrs)
     return;
 
@@ -1666,12 +1662,12 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags)
 	}
     }
 
+  tree late_attrs = NULL_TREE;
   if (processing_template_decl)
     {
       if (check_for_bare_parameter_packs (attributes))
 	return;
-
-      save_template_attributes (&attributes, decl, flags);
+      late_attrs = splice_template_attributes (&attributes, *decl);
     }
 
   cp_check_const_attributes (attributes);
@@ -1717,6 +1713,9 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags)
       decl_attributes (decl, attributes, flags, last_decl);
     }
 
+  if (late_attrs)
+    save_template_attributes (late_attrs, decl, flags);
+
   /* Propagate deprecation out to the template.  */
   if (TREE_DEPRECATED (*decl))
     if (tree ti = get_template_info (*decl))
diff --git a/gcc/testsuite/g++.dg/lto/alignas1_0.C b/gcc/testsuite/g++.dg/lto/alignas1_0.C
new file mode 100644
index 00000000000..a2fc72ad894
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/alignas1_0.C
@@ -0,0 +1,7 @@
+// PR c++/104245
+// { dg-lto-do assemble }
+// { dg-require-effective-target c++11 }
+
+template <typename T> struct A { alignas(T) alignas(int) int a; };
+struct B { B(const char *, const char *, int, int); A<int> b; };
+B c {"", "", 0, 0};


                 reply	other threads:[~2022-01-27 21:55 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=20220127215548.08D503858430@sourceware.org \
    --to=jason@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).