https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69836
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Jason Merrill <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:1e27e7e0985e055b3d4ec92e93976b709fdbe425 commit r14-277-g1e27e7e0985e055b3d4ec92e93976b709fdbe425 Author: Jason Merrill <ja...@redhat.com> Date: Wed Feb 1 17:00:48 2023 -0500 c++: unique friend shenanigans [PR69836] Normally we re-instantiate a function declaration when we start to instantiate the body in case of multiple declarations. In this wacky testcase, this causes a problem because the type of the w_counter parameter depends on its declaration not being in scope yet, so the name lookup only finds the previous declaration. This isn't a problem for member functions, since they aren't subject to argument-dependent lookup. So let's just skip the regeneration for hidden friends. PR c++/69836 gcc/cp/ChangeLog: * pt.cc (regenerate_decl_from_template): Skip unique friends. gcc/testsuite/ChangeLog: * g++.dg/template/friend76.C: New test.