[gcc(refs/vendors/ARM/heads/arm-9-branch)] PR c++/91476 - anon-namespace reference temp clash between TUs.

Joey Ye jye2@gcc.gnu.org
Thu Feb 27 10:39:00 GMT 2020


https://gcc.gnu.org/g:3384aa7af4c4ce193f59d086f507812b88caf113

commit 3384aa7af4c4ce193f59d086f507812b88caf113
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jan 20 14:09:03 2020 -0500

    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.

Diff:
---
 gcc/cp/ChangeLog                                |  6 ++++++
 gcc/cp/call.c                                   |  2 ++
 gcc/testsuite/g++.dg/ext/visibility/ref-temp1.C | 11 +++++++++++
 3 files changed, 19 insertions(+)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 018ab63..0e1557c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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).
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index bc182e2..8e14e89 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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
index 0000000..b56bb52
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/visibility/ref-temp1.C
@@ -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;
+}



More information about the Gcc-cvs mailing list