From: Jason Merrill Date: Wed, 7 Apr 2021 19:38:07 +0000 (-0400) Subject: c++: base template friend [PR52625] X-Git-Tag: basepoints/gcc-12~223 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b40d45cb1930e9aa8a1f9a6a8728fd47ebeeaaac;p=thirdparty%2Fgcc.git c++: base template friend [PR52625] Here we were mistakenly treating the injected-class-name as a partial specialization. gcc/cp/ChangeLog: PR c++/52625 * pt.c (maybe_process_partial_specialization): Check DECL_SELF_REFERENCE_P. gcc/testsuite/ChangeLog: PR c++/52625 * g++.dg/template/friend70.C: New test. --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index a08d08d28340..dee802121e5d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -984,6 +984,10 @@ maybe_process_partial_specialization (tree type) if (CLASS_TYPE_P (type) && CLASSTYPE_LAMBDA_EXPR (type)) return type; + /* An injected-class-name is not a specialization. */ + if (DECL_SELF_REFERENCE_P (TYPE_NAME (type))) + return type; + if (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM) { error ("name of class shadows template template parameter %qD", diff --git a/gcc/testsuite/g++.dg/template/friend70.C b/gcc/testsuite/g++.dg/template/friend70.C new file mode 100644 index 000000000000..54965486f795 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend70.C @@ -0,0 +1,9 @@ +// PR c++/52625 + +template +class base {}; + +class derived : public base +{ + template friend class base; +};