From: Nathaniel Shead Date: Wed, 12 Feb 2025 12:07:43 +0000 (+1100) Subject: c++: Constrain visibility for CNTTPs with internal types [PR118849] X-Git-Tag: basepoints/gcc-16~2049 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0e485b8c85c31856b9f7c91015ac94874b100bd4;p=thirdparty%2Fgcc.git c++: Constrain visibility for CNTTPs with internal types [PR118849] While looking into PR118846 I noticed that we don't currently constrain the linkage of functions involving CNTTPs of internal-linkage types. It seems to me that this would be sensible to do. PR c++/118849 gcc/cp/ChangeLog: * decl2.cc (min_vis_expr_r): Constrain visibility according to the type of decl_constant_var_p decls. gcc/testsuite/ChangeLog: * g++.dg/template/linkage6.C: New test. Signed-off-by: Nathaniel Shead --- diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 593dcaa4e2d..aa9ebca12f8 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -2814,7 +2814,9 @@ min_vis_expr_r (tree *tp, int */*walk_subtrees*/, void *data) /* The ODR allows definitions in different TUs to refer to distinct constant variables with internal or no linkage, so such a reference shouldn't affect visibility (PR110323). FIXME but only if the - lvalue-rvalue conversion is applied. */; + lvalue-rvalue conversion is applied. We still want to restrict + visibility according to the type of the declaration however. */ + tpvis = type_visibility (TREE_TYPE (t)); else if (! TREE_PUBLIC (t)) tpvis = VISIBILITY_ANON; else diff --git a/gcc/testsuite/g++.dg/template/linkage6.C b/gcc/testsuite/g++.dg/template/linkage6.C new file mode 100644 index 00000000000..b86c986568f --- /dev/null +++ b/gcc/testsuite/g++.dg/template/linkage6.C @@ -0,0 +1,13 @@ +// PR c++/118849 +// { dg-do compile { target c++20 } } +// { dg-final { scan-assembler-not "(weak|glob)\[^\n\]*_Z" { xfail powerpc-*-aix* } } } + +namespace { + struct A {}; +} + +template void f() { } + +int main() { + f(); +}