From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 936203858CD1; Thu, 21 Mar 2024 17:54:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 936203858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711043681; bh=pKVpIj7rDSKp3KS39m65hwdk5KeFITNNx2m9TbAs69c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LEyEM4wcFFsmlpcjLE+RvoW4XFBJ2wCDKhsbRQUqsRk8xg3oCJ2uL31MM+ZUznFls GuyaHbHoNhUtXOgbHgyF/dWn/cHQEXZIDlCGKZVDS246Mg+QH+KmKA2pzstxnBku5M 19wVo8lcXZZStkBDPGaOtJJn3YGMueXWf8/iAgGM= From: "cvs-commit 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: Thu, 21 Mar 2024 17:54:40 +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: cvs-commit 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 #10 from GCC Commits --- The trunk branch has been updated by Marek Polacek : https://gcc.gnu.org/g:081f8937cb82da311c224da04b0c6cbd57a8fb5d commit r14-9596-g081f8937cb82da311c224da04b0c6cbd57a8fb5d Author: Marek Polacek Date: Thu Mar 7 20:41:23 2024 -0500 c++: explicit inst of template method not generated [PR110323] Consider constexpr int VAL =3D 1; struct foo { template void bar(typename std::conditional::type = arg) { } }; template void foo::bar<1>(int arg); where we since r11-291 fail to emit the code for the explicit instantiation. That's because cp_walk_subtrees/TYPENAME_TYPE now walks TYPE_CONTEXT ('conditional' here) as well, and in a template finds the B=3D=3DVAL template argument. VAL is constexpr, which implie= s const, which in the global scope implies static.=20 constrain_visibility_for_template then makes "struct conditional<(B =3D=3D VAL), int, float>" non-TREE_PU= BLIC. Then symtab_node::needed_p checks TREE_PUBLIC, sees it's 0, and we don't emit any code. I thought the fix would be some ODR-esque check to not consider constexpr variables/fns that are used just for their value. But it turned out to be tricky. For instance, we can't skip determine_visibility in a template; we can't even skip it for value-dep expressions. For example, no-linkage-expr1.C has using P =3D struct {}*; template void f(int(*)[((P)0, N)]) {} where ((P)0, N) is value-dep, but N is not relevant here: we have to ferret out the anonymous type. When instantiating, it's already gone. This patch uses decl_constant_var_p. This is to implement (an approximation) [basic.def.odr]#14.5.1 and [basic.def.odr]#5.2. PR c++/110323 gcc/cp/ChangeLog: * decl2.cc (min_vis_expr_r) : Do nothing for decl_constant_var_p VAR_DECLs. gcc/testsuite/ChangeLog: * g++.dg/template/explicit-instantiation6.C: New test. * g++.dg/template/explicit-instantiation7.C: New test.=