From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 512103858298; Sat, 1 Apr 2023 14:19:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 512103858298 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680358759; bh=F1tMAmtVID4fJyzokENSw9CumSW+6kMXwrXm3aAvOAA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Uz2p56sCJORdIXls0wSH4DvWIeAVGf6XGWADQHS5BuuhwmB7X96JzvNhOn/Ti/ZrA lz/tBV2gOhJCgXSmjYDTf7RJVbLUV2TY6iq4CLwmiB4ZO73euRs0xx4fJLsXagbfNs Ee0lfN0B5rfpecHuPZhGrXdvWHnFlqmlLCyBTvB4= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/53164] Undefined reference to template function instantiation Date: Sat, 01 Apr 2023 14:19:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.6.2 X-Bugzilla-Keywords: link-failure X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ppalka at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.2 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53164 --- Comment #7 from CVS Commits --- The master branch has been updated by Patrick Palka : https://gcc.gnu.org/g:b5e38b1c166357e2a63d38ae6da7ae5d68fc115b commit r13-6970-gb5e38b1c166357e2a63d38ae6da7ae5d68fc115b Author: Patrick Palka Date: Sat Apr 1 10:19:08 2023 -0400 c++: improve "NTTP argument considered unused" fix [PR53164, PR105848] r13-995-g733a792a2b2e16 worked around the problem of (pointer to) function NTTP arguments not always getting marked as odr-used, by redundantly calling mark_used on the substituted ADDR_EXPR callee of a CALL_EXPR. That is just a narrow workaround however, since it assumes the function is later called, but the use as a template argument alone should constitute an odr-use of the function (since template arguments are an evaluated context, and we're really passing its address); we shouldn't need to subsequently call or otherwise use the function NTTP argument. This patch fixes this in a more general way by walking the template arguments of each specialization that's about to be instantiated and redundantly calling mark_used on all entities used within. As before, the call to mark_used as it worst a no-op, but it compensates for the situation where the specialization was first formed in a template conte= xt in which mark_used is inhibited. Another approach would be to call mark_used whenever we substitute a TEMPLATE_PARM_INDEX, but that would result in many more redundant calls to mark_used compared to this approach. And as the second testcase below illustrates, we also need to walk C++20 class NTTP arguments which can be large and thus expensive to walk repeatedly. The change to invalid_tparm_referent_p is needed to avoid incorrectly rejecting class NTTP arguments containing function pointers as in the testcase. (The third testcase is unrelated to this fix, but it helped rule out an earlier approach I was considering and it seems we don't have existing test coverage for this situation.) PR c++/53164 PR c++/105848 gcc/cp/ChangeLog: * pt.cc (invalid_tparm_referent_p): Accept ADDR_EXPR of FUNCTION_DECL. (instantiate_class_template): Call mark_template_arguments_used. (tsubst_copy_and_build) : Revert r13-995 change. (mark_template_arguments_used): Define. (instantiate_body): Call mark_template_arguments_used. gcc/testsuite/ChangeLog: * g++.dg/template/fn-ptr3a.C: New test. * g++.dg/template/fn-ptr3b.C: New test. * g++.dg/template/fn-ptr4.C: New test.=