From 42ccbf3d11f315dc0752c58efb572451a27f82ce Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Sun, 16 Jul 2006 22:17:20 +0200
Subject: [PATCH] re PR c++/28370 (undefined reference to template class static
 variable in an anonymous namespace)

	PR c++/28370
	* decl2.c (note_vague_linkage_var): Removed.
	(finish_static_data_member_decl): Add decl to pending_statics vector
	directly.  Do it even for non-public decls.

	* g++.dg/template/anon3.C: New test.

From-SVN: r115503
---
 gcc/cp/ChangeLog                      |  7 +++++++
 gcc/cp/decl2.c                        | 12 ++----------
 gcc/testsuite/ChangeLog               |  5 +++++
 gcc/testsuite/g++.dg/template/anon3.C | 20 ++++++++++++++++++++
 4 files changed, 34 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/anon3.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0dd1e8ca4c26..d1eb30fea24e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2006-07-16  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/28370
+	* decl2.c (note_vague_linkage_var): Removed.
+	(finish_static_data_member_decl): Add decl to pending_statics vector
+	directly.  Do it even for non-public decls.
+
 2006-07-15  Lee Millward  <lee.millward@gmail.com>
 
 	PR c++/28292
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index f1a8a77431cd..dfb30f25d936 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -700,14 +700,6 @@ note_vague_linkage_fn (tree decl)
     }
 }
 
-/* Like note_vague_linkage_fn but for variables.  */
-
-static void
-note_vague_linkage_var (tree var)
-{
-  VEC_safe_push (tree, gc, pending_statics, var);
-}
-
 /* We have just processed the DECL, which is a static data member.
    The other parameters are as for cp_finish_decl.  */
 
@@ -723,8 +715,8 @@ finish_static_data_member_decl (tree decl,
      TREE_CHAIN of our decl.  Instead, we modify cp_finish_decl to do
      the right thing, namely, to put this decl out straight away.  */
 
-  if (! processing_template_decl && TREE_PUBLIC (decl))
-    note_vague_linkage_var (decl);
+  if (! processing_template_decl)
+    VEC_safe_push (tree, gc, pending_statics, decl);
 
   if (LOCAL_CLASS_P (current_class_type))
     pedwarn ("local class %q#T shall not have static data member %q#D",
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 68b45a291eca..98eaa25b0666 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2006-07-16  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/28370
+	* g++.dg/template/anon3.C: New test.
+
 2006-07-16  Paul Thomas  <pault@gcc.gnu.org>
 
 	PR fortran/20844
diff --git a/gcc/testsuite/g++.dg/template/anon3.C b/gcc/testsuite/g++.dg/template/anon3.C
new file mode 100644
index 000000000000..eee7acd820f6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/anon3.C
@@ -0,0 +1,20 @@
+// PR c++/28370
+// { dg-do run }
+
+namespace
+{
+  template<typename T> struct A { static int *a; };
+  template<typename T> int *A<T>::a = 0;
+}
+
+int *
+foo ()
+{
+  return A<int>::a;
+}
+
+int
+main ()
+{
+  return foo() != 0;
+}
-- 
GitLab