From: Jason Merrill Date: Mon, 20 Jan 2020 19:09:03 +0000 (-0500) Subject: PR c++/91476 - anon-namespace reference temp clash between TUs. X-Git-Tag: releases/gcc-9.3.0~210 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3384aa7af4c4ce193f59d086f507812b88caf113;p=thirdparty%2Fgcc.git 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 --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 018ab630969f..0e1557c936e2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-01-21 Jason Merrill + + 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 PR c++/92531 - ICE with noexcept(lambda). diff --git a/gcc/cp/call.c b/gcc/cp/call.c index bc182e2f6da0..8e14e89d5d49 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 000000000000..b56bb52a73cb --- /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; +}