From bc95e478febd35e0d1fb13c1833d2383ad0e7d18 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 6 May 2020 12:09:59 -0700 Subject: [PATCH] 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. --- 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(-) create mode 100644 gcc/testsuite/g++.dg/ext/attr-parm-1.C 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 + + 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 * 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 a(b (*)()); + template a(b(__attribute__((fastcall)) *c)()); +}; -- 2.30.2