From: Jason Merrill Date: Tue, 21 Mar 2023 19:15:27 +0000 (-0400) Subject: c++: attribute on dtor in template [PR108795] X-Git-Tag: releases/gcc-12.3.0~53 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1c1a9a0b60a9a182bcff79084e5ac367a6329bc2;p=thirdparty%2Fgcc.git c++: attribute on dtor in template [PR108795] Since r7-2549 we were throwing away the explicit C:: when we found that ~C has an attribute that we treat as making its type dependent. PR c++/108795 gcc/cp/ChangeLog: * semantics.cc (finish_id_expression_1): Check scope before returning id_expression. gcc/testsuite/ChangeLog: * g++.dg/ext/attr-tsafe1.C: New test. --- diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index ae6cf71b4f59..ee0db331f34c 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -4152,6 +4152,7 @@ finish_id_expression_1 (tree id_expression, : CP_ID_KIND_UNQUALIFIED))); if (dependent_p + && !scope && DECL_P (decl) && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl))) /* Dependent type attributes on the decl mean that the TREE_TYPE is diff --git a/gcc/testsuite/g++.dg/ext/attr-tsafe1.C b/gcc/testsuite/g++.dg/ext/attr-tsafe1.C new file mode 100644 index 000000000000..20c319f154dc --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-tsafe1.C @@ -0,0 +1,14 @@ +// PR c++/108795 + +template void g (T x) +{ + struct C + { + __attribute__((transaction_safe)) ~C(); + }; + C::~C(); // { dg-error "" } +} +void f () +{ + g (5); +}