From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 283B9385DC2F; Fri, 8 Mar 2024 17:43:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 283B9385DC2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709919790; bh=kd3tBxWG+PCEimCBQPDolFu9/y9T9cmajcyGgH9gthY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=vt/yqfUdU9Tu0VFKi2l9sXVSrJhbymt+9FiPJx7vaBdqEdNea32+LFFSWg9r3mCcg 8z5eb1tNLP2mRrZB2kMz1vRgNEdKPSKFImVcW8u1m5rXMyD2e1OdT81bFCqcqMzaGc YKIGw1CPGKWS0R6IEHXn04v6y0Kql5Hb7ySLvPPI= From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110323] [11/12/13/14 Regression] Code for explicit instantiation of template method of template class not generated Date: Fri, 08 Mar 2024 17:43:09 +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: 11.1.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.5 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=3D110323 --- Comment #8 from Marek Polacek --- (In reply to Patrick Palka from comment #7) > I noticed we emit the function if we turn it into a non-member: >=20 > #include >=20 > constexpr int VAL =3D 1; >=20 > template > void bar(typename std::conditional::type arg)= { > } >=20 > template void bar<1>(int arg); >=20 > I wonder why this bug seems specific to member functions? Good question. It's because in this case bar is marked as force_output her= e: /* When not optimizing, also output the static functions. (see PR24561), but don't do so for always_inline functions, functions declared inline and nested functions. These were optimized out in the original implementation and it is unclear whether we want to change the behavior here. */ if (((!opt_for_fn (decl, optimize) || flag_keep_static_functions || node->no_reorder) && !node->cpp_implicit_alias && !DECL_DISREGARD_INLINE_LIMITS (decl) && !DECL_DECLARED_INLINE_P (decl) && !(DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) =3D=3D FUNCTION_DECL)) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl)) node->force_output =3D 1; and when deciding if we ought to emit the fn in symtab_node::needed_p we do: /* If the user told us it is used, then it must be so. */ if (force_output) return true; With -O the fn isn't emitted.=