diff options
author | Marek Polacek <polacek@redhat.com> | 2024-03-07 20:41:23 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-03-21 13:47:10 -0400 |
commit | 081f8937cb82da311c224da04b0c6cbd57a8fb5d (patch) | |
tree | b6d5e208193b25335f561cbb138115abbdabd765 /libgcc | |
parent | a2fe34e0b993d5fb879d75ddb42b24b45c4b7242 (diff) | |
download | gcc-081f8937cb82da311c224da04b0c6cbd57a8fb5d.zip gcc-081f8937cb82da311c224da04b0c6cbd57a8fb5d.tar.gz gcc-081f8937cb82da311c224da04b0c6cbd57a8fb5d.tar.bz2 |
c++: explicit inst of template method not generated [PR110323]
Consider
constexpr int VAL = 1;
struct foo {
template <int B>
void bar(typename std::conditional<B==VAL, int, float>::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==VAL template argument. VAL is constexpr, which implies const,
which in the global scope implies static. constrain_visibility_for_template
then makes "struct conditional<(B == VAL), int, float>" non-TREE_PUBLIC.
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 = struct {}*;
template <int N>
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) <case VAR_DECL>: 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.
Diffstat (limited to 'libgcc')
0 files changed, 0 insertions, 0 deletions