From a2507277ed143a8f75f5a60f43541fc3d714aede Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 18 Aug 2003 12:44:22 +0000 Subject: [PATCH] pt.c (instantiate_class_template): Push to class's scope before tsubsting base. 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 | 5 ++++ gcc/cp/pt.c | 8 ++++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/template/error2.C | 2 +- gcc/testsuite/g++.dg/template/scope2.C | 34 ++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/scope2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4a3d9819e69..19562e612a6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2003-08-18 Nathan Sidwell + + * pt.c (instantiate_class_template): Push to class's scope before + tsubsting base. + Sun Aug 17 10:05:38 CEST 2003 Jan Hubicka PR C++/11702 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d97463bc390..e0dfcb78774 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 504682624eb..6a38f18f506 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-08-18 Nathan Sidwell + + * g++.dg/template/scope2.C: New test. + * g++.dg/template/error2.C: Correct dg-error + 2003-08-18 Richard Sandiford * gcc.c-torture/compile/mipscop*.c: Turn into compile-only tests. diff --git a/gcc/testsuite/g++.dg/template/error2.C b/gcc/testsuite/g++.dg/template/error2.C index 1ce9b6f5174..0f3e975cd4f 100644 --- a/gcc/testsuite/g++.dg/template/error2.C +++ b/gcc/testsuite/g++.dg/template/error2.C @@ -14,7 +14,7 @@ template struct Derived { class Nested : public X - { // { 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 index 00000000000..79b520cbeab --- /dev/null +++ b/gcc/testsuite/g++.dg/template/scope2.C @@ -0,0 +1,34 @@ +// { dg-do compile } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 15 Aug 2003 + +// checked instantiated bases in wrong scope. + +class Helper {}; + +template struct X { }; + +template class Base +{ + protected: + typedef Helper H; +}; + +template +struct Derived : Base +{ + typedef Base Parent; + typedef typename Parent::H H; + + class Nested : public X {}; + + Nested m; + + void Foo (); +}; + +void Foo (Derived &x) +{ + x.Foo (); +} -- 2.30.2