OSDN Git Service

PR c++/13262
authorlerdsuwa <lerdsuwa@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Dec 2003 14:14:48 +0000 (14:14 +0000)
committerlerdsuwa <lerdsuwa@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Dec 2003 14:14:48 +0000 (14:14 +0000)
* pt.c (instantiate_decl): Wrap push_nested_class and
pop_nested_class around cp_finish_decl call for static member
variable.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@74780 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/access13.C [new file with mode: 0644]

index 8d9d9a3..1789243 100644 (file)
@@ -1,3 +1,10 @@
+2003-12-18  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/13262
+       * pt.c (instantiate_decl): Wrap push_nested_class and
+       pop_nested_class around cp_finish_decl call for static member
+       variable.
+
 2003-12-18  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
 
        PR c++/9154
index 1a03bba..8445dce 100644 (file)
@@ -11115,10 +11115,20 @@ instantiate_decl (tree d, int defer_ok)
          /* Mark D as instantiated so that recursive calls to
             instantiate_decl do not try to instantiate it again.  */
          DECL_TEMPLATE_INSTANTIATED (d) = 1;
+         /* This is done in analogous to `start_decl'.  It is
+            required for correct access checking.  */
+         push_nested_class (DECL_CONTEXT (d));
          cp_finish_decl (d, 
                          (!DECL_INITIALIZED_IN_CLASS_P (d) 
                           ? DECL_INITIAL (d) : NULL_TREE),
                          NULL_TREE, 0);
+         /* Normally, pop_nested_class is called by cp_finish_decl
+            above.  But when instantiate_decl is triggered during
+            instantiate_class_template processing, its DECL_CONTEXT
+            is still not completed yet, and pop_nested_class isn't
+            called.  */
+         if (!COMPLETE_TYPE_P (DECL_CONTEXT (d)))
+           pop_nested_class ();
        }
     }
   else if (TREE_CODE (d) == FUNCTION_DECL)
index 33e5eb8..009c8e9 100644 (file)
@@ -1,3 +1,8 @@
+2003-12-18  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/13262
+       * g++.dg/template/access13.C: New test.
+
 2003-12-18  Ulrich Weigand  <uweigand@de.ibm.com>
 
        * gcc.dg/20031216-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/template/access13.C b/gcc/testsuite/g++.dg/template/access13.C
new file mode 100644 (file)
index 0000000..3a1442b
--- /dev/null
@@ -0,0 +1,16 @@
+// { dg-do compile }
+
+// Origin: Francesco Monica <fmonica@ce.unipr.it>
+
+// PR c++/13262: Access checking during instantiation of static data
+// member.
+
+template <typename T> class Aclass {
+  private:
+    Aclass() {}
+    static Aclass instance;
+};
+
+template <typename T> Aclass<T> Aclass<T>::instance;
+
+template class Aclass<int>;