https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86747
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-8 branch has been updated by Jason Merrill <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:3d99aab56d7237bb8260653ed07ca8b182fbf975 commit r8-10073-g3d99aab56d7237bb8260653ed07ca8b182fbf975 Author: Alexandre Oliva <aol...@redhat.com> Date: Tue Feb 25 21:29:03 2020 -0500 c++: tsubst friend tpl ctxt before looking it up for dupes [PR86747] When a member template is redeclared as a friend, we enter the context of the member before looking it up, and then we check that the decls are compatible. However, when the member template references template types of the enclosing context, say an enclosing template class, the compare fails because the friend decl is already tsubsted, whereas the looked up name isn't. The problem is that the enclosing context is taken from the friend declaration before tsubsting it, so we look up in the context of the generic template instead of that of the tsubsted one we're specializing. The solution is to tsubst the enclosing context when it's a non-namespace scope. gcc/cp/ChangeLog 2020-02-25 Alexandre Oliva <aol...@redhat.com> PR c++/86747 * pt.c (tsubst_friend_class): Enter tsubsted class context. gcc/testsuite/ChangeLog 2020-02-25 Alexandre Oliva <aol...@redhat.com> PR c++/86747 * g++.dg/pr86747.C: New.