summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-02 17:49:21 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-02 17:49:21 +0000
commitca1f96a60ea7fea59e6ef43f13c93c3019460b93 (patch)
treee654734c754b142e86f0adfa0fd4225aa223605a
parentca74084af0f4e73002f844996b7d28a583c92d2a (diff)
downloadppe42-gcc-ca1f96a60ea7fea59e6ef43f13c93c3019460b93.tar.gz
ppe42-gcc-ca1f96a60ea7fea59e6ef43f13c93c3019460b93.zip
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123432 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/decl.c22
-rw-r--r--gcc/cp/typeck.c10
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/ext/visibility/anon3.C16
6 files changed, 54 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 49211160400..755115e4a93 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2007-03-30 Jason Merrill <jason@redhat.com>
+
+ 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.
+
2007-03-31 Richard Guenther <rguenther@suse.de>
* optimize.c (maybe_clone_body): Replace splay-tree usage by
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 2d20246a244..3b3821ef257 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4742,6 +4742,7 @@ extern bool comp_ptr_ttypes_const (tree, tree);
extern int ptr_reasonably_similar (tree, tree);
extern tree build_ptrmemfunc (tree, tree, int, bool);
extern int cp_type_quals (tree);
+extern bool cp_type_readonly (tree);
extern bool cp_has_mutable_p (tree);
extern bool at_least_as_qualified_p (tree, tree);
extern void cp_apply_type_quals_to_decl (int, tree);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 833e7b8e43a..76be0558faa 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);
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 6478b3725bd..a5a33451cf9 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6897,6 +6897,16 @@ cp_type_quals (tree type)
return TYPE_QUALS (type);
}
+/* Returns nonzero if the TYPE is const from a C++ perspective: look inside
+ arrays. */
+
+bool
+cp_type_readonly (tree type)
+{
+ type = strip_array_types (type);
+ return TYPE_READONLY (type);
+}
+
/* Returns nonzero if the TYPE contains a mutable member. */
bool
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3b4d65abef7..ca830148bc4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-04-02 Jason Merrill <jason@redhat.com>
+
+ PR c++/31187
+ * g++.dg/ext/visibility/anon3.C: New test.
+
2007-04-01 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/31052
diff --git a/gcc/testsuite/g++.dg/ext/visibility/anon3.C b/gcc/testsuite/g++.dg/ext/visibility/anon3.C
new file mode 100644
index 00000000000..9def559d253
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/visibility/anon3.C
@@ -0,0 +1,16 @@
+// PR c++/31187
+// Bug: the repeated declaration was confusing the compiler into
+// thinking that foo1 had language internal linkage.
+
+class foo { };
+
+namespace
+{
+ extern foo foo1;
+ foo foo1;
+}
+
+template< foo * >
+class bar { };
+
+bar< &foo1 > bar1;
OpenPOWER on IntegriCloud