https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97010
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-10 branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>: https://gcc.gnu.org/g:257bbf154cd2b83eb02c99db73537e3b8ba3a6e7 commit r10-8915-g257bbf154cd2b83eb02c99db73537e3b8ba3a6e7 Author: Marek Polacek <pola...@redhat.com> Date: Thu Sep 10 17:27:43 2020 -0400 c++: Fix P0846 (ADL and function templates) in template [PR97010] To quickly recap, P0846 says that a name is also considered to refer to a template if it is an unqualified-id followed by a < and name lookup finds either one or more functions or finds nothing. In a template, when parsing a function call that has type-dependent arguments, we can't perform ADL right away so we set KOENIG_LOOKUP_P in the call to remember to do it when instantiating the call (tsubst_copy_and_build/CALL_EXPR). When the called function is a function template, we represent the call with a TEMPLATE_ID_EXPR; usually the operand is an OVERLOAD. In the P0846 case though, the operand can be an IDENTIFIER_NODE, when name lookup found nothing when parsing the template name. But we weren't handling this correctly in tsubst_copy_and_build. First we need to pass the FUNCTION_P argument from <case TEMPLATE_ID_EXPR> to <case IDENTIFIER_NODE>, otherwise we give a bogus error. And then in <case CALL_EXPR> we need to perform ADL. The rest of the changes is to give better errors when ADL didn't find anything. gcc/cp/ChangeLog: PR c++/97010 * pt.c (tsubst_copy_and_build) <case TEMPLATE_ID_EXPR>: Call tsubst_copy_and_build explicitly instead of using the RECUR macro. Handle a TEMPLATE_ID_EXPR with an IDENTIFIER_NODE as its operand. <case CALL_EXPR>: Perform ADL for a TEMPLATE_ID_EXPR with an IDENTIFIER_NODE as its operand. gcc/testsuite/ChangeLog: PR c++/97010 * g++.dg/cpp2a/fn-template21.C: New test. * g++.dg/cpp2a/fn-template22.C: New test. (cherry picked from commit 635072248a426c933c74ef4431e82401249b6218)