[gcc/devel/ranger] c++: QT overload regression with attribute [PR94946]

Aldy Hernandez aldyh@gcc.gnu.org
Wed Jun 17 21:08:24 GMT 2020


https://gcc.gnu.org/g:bc95e478febd35e0d1fb13c1833d2383ad0e7d18

commit bc95e478febd35e0d1fb13c1833d2383ad0e7d18
Author: Nathan Sidwell <nathan@acm.org>
Date:   Wed May 6 12:09:59 2020 -0700

    c++: QT overload regression with attribute [PR94946]
    
    Jason's fix for 90570 & 79585 was a bit overzealous.  Dependent attribs should still
    attach to a parameter decl.
    
                * decl.c (grokdeclarator): Don't splice template attributes in
                parm context -- they can apply to the parm.

Diff:
---
 gcc/cp/ChangeLog                       | 6 ++++++
 gcc/cp/decl.c                          | 9 ++++++---
 gcc/testsuite/g++.dg/ext/attr-parm-1.C | 6 ++++++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 218ed03c019..7e41433707e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-06  Nathan Sidwell  <nathan@acm.org>
+
+	PR c++/94946
+	* decl.c (grokdeclarator): Don't splice template attributes in
+	parm context -- they can apply to the parm.
+
 2020-05-05  Iain Sandoe  <iain@sandoe.co.uk>
 
 	* coroutines.cc: Remove references to n4849 throughout.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3e7ed98fed3..232d7ed4a14 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -11940,9 +11940,12 @@ grokdeclarator (const cp_declarator *declarator,
 	    attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
 	  if (declarator->kind == cdk_array)
 	    attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
-	  /* Assume that any attributes that get applied late to templates will
-	     DTRT when applied to the declaration as a whole.  */
-	  tree late_attrs = splice_template_attributes (&attrs, type);
+	  tree late_attrs = NULL_TREE;
+	  if (decl_context != PARM)
+	    /* Assume that any attributes that get applied late to
+	       templates will DTRT when applied to the declaration
+	       as a whole.  */
+	    late_attrs = splice_template_attributes (&attrs, type);
 	  returned_attrs = decl_attributes (&type,
 					    chainon (returned_attrs, attrs),
 					    attr_flags);
diff --git a/gcc/testsuite/g++.dg/ext/attr-parm-1.C b/gcc/testsuite/g++.dg/ext/attr-parm-1.C
new file mode 100644
index 00000000000..cc53a2ce328
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attr-parm-1.C
@@ -0,0 +1,6 @@
+// { dg-do compile { target { { i?86-*-* x86_64-*-* } && ia32 } } }
+// PR 94946
+class a {
+  template <typename b> a(b (*)());
+  template <typename b> a(b(__attribute__((fastcall)) *c)());
+};


More information about the Gcc-cvs mailing list