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 <nathanieloshead@gmail.com>
/* 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
--- /dev/null
+// 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 <auto Q> void f() { }
+
+int main() {
+ f<A{}>();
+}