aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-06-03 12:35:12 -0400
committerJason Merrill <jason@redhat.com>2022-06-03 13:44:44 -0400
commit284ae8b46f5eef74c0b660a87a7169497f559e73 (patch)
tree7360cdd27f31c55d3015b8b8591880ddc25c508b /gcc/cp
parent44a5bd6d933d86ed988fc4695aa00f122cf83eb4 (diff)
downloadgcc-284ae8b46f5eef74c0b660a87a7169497f559e73.zip
gcc-284ae8b46f5eef74c0b660a87a7169497f559e73.tar.gz
gcc-284ae8b46f5eef74c0b660a87a7169497f559e73.tar.bz2
c++: redeclared hidden friend [PR105761]
Here, when we see the second declaration of f we match it with the first one, copy over DECL_TEMPLATE_INFO, and then try to use it when parsing the definition, leading to confusion. PR c++/105761 gcc/cp/ChangeLog: * decl.cc (duplicate_decls): Don't copy DECL_TEMPLATE_INFO from a hidden friend. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/auto-fn64.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/decl.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index e0d397d..90b12d6 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2654,7 +2654,13 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
if (LANG_DECL_HAS_MIN (newdecl))
{
DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
- if (DECL_TEMPLATE_INFO (newdecl))
+ if (new_defines_function
+ && DECL_TEMPLATE_INFO (olddecl)
+ && DECL_UNIQUE_FRIEND_P (DECL_TEMPLATE_RESULT
+ (DECL_TI_TEMPLATE (olddecl))))
+ /* Don't copy template info from a non-template friend declaration
+ in a class template (PR105761). */;
+ else if (DECL_TEMPLATE_INFO (newdecl))
{
new_template_info = DECL_TEMPLATE_INFO (newdecl);
if (DECL_TEMPLATE_INSTANTIATION (olddecl)
@@ -2662,8 +2668,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
/* Remember the presence of explicit specialization args. */
TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
= TINFO_USED_TEMPLATE_ID (new_template_info);
+ DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
}
- DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
+ else
+ DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
}
if (DECL_DECLARES_FUNCTION_P (newdecl))