This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH]: Instantiation context for bases
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Mark Mitchell <mitchell at codesourcery dot com>
- Date: Mon, 18 Aug 2003 13:45:04 +0100
- Subject: [C++ PATCH]: Instantiation context for bases
- Organization: Codesourcery LLC
Hi,
I've installed the attached patch, which fixes an incorrect accessibility
error. The accessibility of bases (& their template args) of a templated
class should be checked in the scope in which the templated class resides.
This patch matches code in the parser for non-templated classes.
booted & tested on i686-pc-linux-gnu, installed as obvious.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2003-08-18 Nathan Sidwell <nathan@codesourcery.com>
* pt.c (instantiate_class_template): Push to class's scope before
tsubsting base.
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.758
diff -c -3 -p -r1.758 pt.c
*** cp/pt.c 15 Aug 2003 12:15:56 -0000 1.758
--- cp/pt.c 18 Aug 2003 12:30:40 -0000
*************** instantiate_class_template (tree type)
*** 5173,5180 ****
--- 5173,5186 ----
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)
*************** instantiate_class_template (tree type)
*** 5201,5206 ****
--- 5207,5214 ----
/* 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
// { 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 ();
}