aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2007-04-02 13:49:21 -0400
committerJason Merrill <jason@gcc.gnu.org>2007-04-02 13:49:21 -0400
commitc3b7031d9643c03eed891a96cfb528a4f5ffa78e (patch)
treee654734c754b142e86f0adfa0fd4225aa223605a /gcc/cp/decl.c
parenta0036853d2b6260c0a322da8d411dcebd3ac4f9e (diff)
downloadgcc-c3b7031d9643c03eed891a96cfb528a4f5ffa78e.zip
gcc-c3b7031d9643c03eed891a96cfb528a4f5ffa78e.tar.gz
gcc-c3b7031d9643c03eed891a96cfb528a4f5ffa78e.tar.bz2
re PR c++/31187 (extern declaration of variable in anonymous namespace prevents use of its address as template argument)
PR c++/31187 * typeck.c (cp_type_readonly): New fn. * cp-tree.h: Declare it. * decl.c (start_decl): Set implicit DECL_THIS_STATIC here. (cp_finish_decl): Not here. * g++.dg/ext/visibility/anon3.C: New test. From-SVN: r123432
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 833e7b8..76be055 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3797,6 +3797,7 @@ start_decl (const cp_declarator *declarator,
tree decl;
tree type, tem;
tree context;
+ bool was_public;
*pushed_scope_p = NULL_TREE;
@@ -3951,6 +3952,8 @@ start_decl (const cp_declarator *declarator,
decl);
}
+ was_public = TREE_PUBLIC (decl);
+
/* Enter this declaration into the symbol table. */
tem = maybe_push_decl (decl);
@@ -3971,6 +3974,17 @@ start_decl (const cp_declarator *declarator,
&& !have_global_bss_p ())
DECL_COMMON (tem) = 1;
+ if (TREE_CODE (tem) == VAR_DECL
+ && DECL_NAMESPACE_SCOPE_P (tem) && !TREE_PUBLIC (tem) && !was_public
+ && !DECL_THIS_STATIC (tem) && !DECL_ARTIFICIAL (tem))
+ {
+ /* This is a const variable with implicit 'static'. Set
+ DECL_THIS_STATIC so we can tell it from variables that are
+ !TREE_PUBLIC because of the anonymous namespace. */
+ gcc_assert (cp_type_readonly (TREE_TYPE (tem)));
+ DECL_THIS_STATIC (tem) = 1;
+ }
+
if (!processing_template_decl && TREE_CODE (tem) == VAR_DECL)
start_decl_1 (tem, initialized);
@@ -5283,14 +5297,6 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
{
layout_var_decl (decl);
maybe_commonize_var (decl);
- if (DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl)
- && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl))
- {
- /* This is a const variable with implicit 'static'. Set
- DECL_THIS_STATIC so we can tell it from variables that are
- !TREE_PUBLIC because of the anonymous namespace. */
- DECL_THIS_STATIC (decl) = 1;
- }
}
make_rtl_for_nonlocal_decl (decl, init, asmspec);