aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/tree.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2024-07-25 19:00:23 -0400
committerThomas Koenig <tkoenig@gcc.gnu.org>2024-07-28 19:05:59 +0200
commitc0fc7ff00ebeea647bff595b506ea6423778df75 (patch)
tree363fff269f108ec453ded0c80f8e9e9e25fac391 /gcc/cp/tree.cc
parentda90f2fa84672a56f715265774fa0ef2806d62f6 (diff)
downloadgcc-c0fc7ff00ebeea647bff595b506ea6423778df75.zip
gcc-c0fc7ff00ebeea647bff595b506ea6423778df75.tar.gz
gcc-c0fc7ff00ebeea647bff595b506ea6423778df75.tar.bz2
c++: alias of alias tmpl with dependent attrs [PR115897]
As a follow-up to r15-2047-g7954bb4fcb6fa8, we also need to consider dependent attributes when recursing into a non-template alias that names a dependent alias template specialization (and so STF_STRIP_DEPENDENT is set), otherwise in the first testcase below we undesirably strip B all the way to T instead of to A<T>. We also need to move the typedef recursion case of strip_typedefs up to get checked before the compound type recursion cases. Otherwise for C below (which ultimately aliases T*) we end up stripping it to T* instead of to A<T*> because the POINTER_TYPE recursion dominates the typedef recursion. It also means we issue an unexpected extra error in the third testcase below. Ideally we would also want to consider dependent attributes on non-template aliases, so that we accept the second testcase below, but making that work correctly would require broader changes to e.g. structural_comptypes. PR c++/115897 gcc/cp/ChangeLog: * tree.cc (strip_typedefs): Move up the typedef recursion case. Never strip a dependent alias template-id that has dependent attributes. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/alias-decl-78.C: New test. * g++.dg/cpp0x/alias-decl-79.C: New test. * g++.dg/cpp0x/alias-decl-pr92206-1a.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/cp/tree.cc')
-rw-r--r--gcc/cp/tree.cc51
1 files changed, 29 insertions, 22 deletions
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 250239e..f2001ac 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -1607,11 +1607,32 @@ strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
if (t == TYPE_CANONICAL (t))
return t;
- if (!(flags & STF_STRIP_DEPENDENT)
- && dependent_alias_template_spec_p (t, nt_opaque))
- /* DR 1558: However, if the template-id is dependent, subsequent
- template argument substitution still applies to the template-id. */
- return t;
+ if (typedef_variant_p (t))
+ {
+ if ((flags & STF_USER_VISIBLE)
+ && !user_facing_original_type_p (t))
+ return t;
+
+ if (alias_template_specialization_p (t, nt_opaque))
+ {
+ if (dependent_alias_template_spec_p (t, nt_opaque)
+ && (!(flags & STF_STRIP_DEPENDENT)
+ || any_dependent_type_attributes_p (DECL_ATTRIBUTES
+ (TYPE_NAME (t)))))
+ /* DR 1558: However, if the template-id is dependent, subsequent
+ template argument substitution still applies to the template-id. */
+ return t;
+ }
+ else
+ /* If T is a non-template alias or typedef, we can assume that
+ instantiating its definition will hit any substitution failure,
+ so we don't need to retain it here as well. */
+ flags |= STF_STRIP_DEPENDENT;
+
+ result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
+ remove_attributes, flags);
+ goto stripped;
+ }
switch (TREE_CODE (t))
{
@@ -1805,23 +1826,9 @@ strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
}
if (!result)
- {
- if (typedef_variant_p (t))
- {
- if ((flags & STF_USER_VISIBLE)
- && !user_facing_original_type_p (t))
- return t;
- /* If T is a non-template alias or typedef, we can assume that
- instantiating its definition will hit any substitution failure,
- so we don't need to retain it here as well. */
- if (!alias_template_specialization_p (t, nt_opaque))
- flags |= STF_STRIP_DEPENDENT;
- result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
- remove_attributes, flags);
- }
- else
- result = TYPE_MAIN_VARIANT (t);
- }
+ result = TYPE_MAIN_VARIANT (t);
+
+stripped:
/*gcc_assert (!typedef_variant_p (result)
|| dependent_alias_template_spec_p (result, nt_opaque)
|| ((flags & STF_USER_VISIBLE)