]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
pt.c (instantiate_class_template): Push to class's scope before tsubsting base.
authorNathan Sidwell <nathan@codesourcery.com>
Mon, 18 Aug 2003 12:44:22 +0000 (12:44 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Mon, 18 Aug 2003 12:44:22 +0000 (12:44 +0000)
cp:
* pt.c (instantiate_class_template): Push to class's scope before
tsubsting base.
testsuite:
* g++.dg/template/scope2.C: New test.
* g++.dg/template/error2.C: Correct dg-error

From-SVN: r70540

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

index 4a3d9819e691c497aa79d025d68b5844ac2c26ab..19562e612a61ce9765ee546a4465a0b8f2a051f7 100644 (file)
@@ -1,3 +1,8 @@
+2003-08-18  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * pt.c (instantiate_class_template): Push to class's scope before
+       tsubsting base.
+
 Sun Aug 17 10:05:38 CEST 2003  Jan Hubicka  <jh@suse.cz>
 
        PR C++/11702
index d97463bc3907100360371ac97720285a7b2b3621..e0dfcb787742da035e3b91ef3e6518399cebbf55 100644 (file)
@@ -5173,8 +5173,14 @@ instantiate_class_template (tree type)
       tree base_list = NULL_TREE;
       tree pbases = BINFO_BASETYPES (pbinfo);
       tree paccesses = BINFO_BASEACCESSES (pbinfo);
+      tree context = TYPE_CONTEXT (type);
       int i;
 
+      /* We must enter the scope containing the type, as that is where
+        the accessibility of types named in dependent bases are
+        looked up from.  */
+      push_scope (context ? context : global_namespace);
+  
       /* Substitute into each of the bases to determine the actual
         basetypes.  */
       for (i = 0; i < TREE_VEC_LENGTH (pbases); ++i)
@@ -5201,6 +5207,8 @@ instantiate_class_template (tree type)
       /* Now call xref_basetypes to set up all the base-class
         information.  */
       xref_basetypes (type, base_list);
+
+      pop_scope (context ? context : global_namespace);
     }
 
   /* Now that our base classes are set up, enter the scope of the
index 504682624eb22fd1774169e2f065f6b91bcda5d4..6a38f18f506c64312314b09b8485aaf1b61622ac 100644 (file)
@@ -1,3 +1,8 @@
+2003-08-18  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.dg/template/scope2.C: New test.
+       * g++.dg/template/error2.C: Correct dg-error
+
 2003-08-18  Richard Sandiford  <rsandifo@redhat.com>
 
        * gcc.c-torture/compile/mipscop*.c: Turn into compile-only tests.
index 1ce9b6f5174ea54aa0bb9b42d7e11b01737b03bd..0f3e975cd4ff843429db936dcdf8e263e31ca368 100644 (file)
@@ -14,7 +14,7 @@ template<class T >
 struct Derived
 {
   class Nested : public X<T>
-  { // { dg-error "instantiated"
+  { // { dg-error "instantiated" "" }
   };
   
   Nested m; // { dg-error "instantiated" "" }
diff --git a/gcc/testsuite/g++.dg/template/scope2.C b/gcc/testsuite/g++.dg/template/scope2.C
new file mode 100644 (file)
index 0000000..79b520c
--- /dev/null
@@ -0,0 +1,34 @@
+// { dg-do compile }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 15 Aug 2003 <nathan@codesourcery.com>
+
+// checked instantiated bases in wrong scope.
+
+class Helper {};
+
+template<class T> struct X { };
+
+template<class T> class Base
+{
+  protected:
+  typedef Helper H;
+};
+
+template<class T >
+struct Derived : Base<T>
+{
+  typedef Base<T> Parent;
+  typedef typename Parent::H H;
+  
+  class Nested : public X<H> {};
+  
+  Nested m;
+  
+  void Foo ();
+};
+
+void Foo (Derived<char> &x)
+{
+  x.Foo ();
+}