]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/91476 - anon-namespace reference temp clash between TUs.
authorJason Merrill <jason@redhat.com>
Mon, 20 Jan 2020 19:09:03 +0000 (14:09 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 21 Jan 2020 15:20:27 +0000 (10:20 -0500)
* call.c (make_temporary_var_for_ref_to_temp): Clear TREE_PUBLIC
if DECL is in the anonymous namespace.

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/ext/visibility/ref-temp1.C [new file with mode: 0644]

index 018ab630969fd0e721fb8ee48268550614be9bdc..0e1557c936e21967f5a2accb56be62afcead130b 100644 (file)
@@ -1,3 +1,9 @@
+2020-01-21  Jason Merrill  <jason@redhat.com>
+
+       PR c++/91476 - anon-namespace reference temp clash between TUs.
+       * call.c (make_temporary_var_for_ref_to_temp): Clear TREE_PUBLIC
+       if DECL is in the anonymous namespace.
+
 2020-01-17  Jason Merrill  <jason@redhat.com>
 
        PR c++/92531 - ICE with noexcept(lambda).
index bc182e2f6da01ae3a572a740c799d1bd10412028..8e14e89d5d498367ebfafb1d00bb2167322c8fb8 100644 (file)
@@ -11424,6 +11424,8 @@ make_temporary_var_for_ref_to_temp (tree decl, tree type)
 
       TREE_STATIC (var) = TREE_STATIC (decl);
       TREE_PUBLIC (var) = TREE_PUBLIC (decl);
+      if (decl_anon_ns_mem_p (decl))
+       TREE_PUBLIC (var) = 0;
       if (vague_linkage_p (decl))
        comdat_linkage (var);
 
diff --git a/gcc/testsuite/g++.dg/ext/visibility/ref-temp1.C b/gcc/testsuite/g++.dg/ext/visibility/ref-temp1.C
new file mode 100644 (file)
index 0000000..b56bb52
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/91476
+// Test that hidden and internal visibility propagates to reference temps.
+
+// { dg-final { scan-assembler-not "(weak|globl)\[^\n\]*_ZGRN12_GLOBAL__N_13fooE_" } }
+namespace { const int &foo = 1; }
+
+const void *volatile p;
+int main()
+{
+  p = &foo;
+}