From cab7a9a3b95c833df6d0175a9a287a9a767879c8 Mon Sep 17 00:00:00 2001 From: Kriang Lerdsuwanakij Date: Thu, 19 Dec 2002 14:45:19 +0000 Subject: [PATCH] re PR c++/3663 (G++ doesn't check access control during template instanation) PR c++/3663 * pt.c (lookup_template_class): Copy TREE_PRIVATE and TREE_PROTECTED to created decl nodes. * g++.dg/template/access7.C: New test. From-SVN: r60307 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/access7.C | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/access7.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index dbf094257ab..042e0c0ed9d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2002-12-18 Kriang Lerdsuwanakij + + PR c++/3663 + * pt.c (lookup_template_class): Copy TREE_PRIVATE and + TREE_PROTECTED to created decl nodes. + 2002-12-18 Mark Mitchell * class.c (build_base_field): Do not set DECL_PACKED on the diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 275605e9d9e..33a84a3aa62 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4235,6 +4235,11 @@ lookup_template_class (d1, arglist, in_decl, context, entering_scope, complain) else type_decl = TYPE_NAME (t); + TREE_PRIVATE (type_decl) + = TREE_PRIVATE (TYPE_STUB_DECL (template_type)); + TREE_PROTECTED (type_decl) + = TREE_PROTECTED (TYPE_STUB_DECL (template_type)); + /* Set up the template information. We have to figure out which template is the immediate parent if this is a full instantiation. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e4b303c79c5..a1510c04a33 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2002-11-18 Kriang Lerdsuwanakij + + PR c++/3663 + * g++.dg/template/access7.C: New test. + 2002-12-18 Nick Clifton * lib/g++.exp (g++_include_flags): Only invoke testsuite_flags if diff --git a/gcc/testsuite/g++.dg/template/access7.C b/gcc/testsuite/g++.dg/template/access7.C new file mode 100644 index 00000000000..92d4c68db39 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/access7.C @@ -0,0 +1,18 @@ +// { dg-do compile } + +// PR c++/3663 +// Enforce access of nested type. + +template +class S { + class T {}; // { dg-error "private" } +}; + +template +typename A::T* f (A) { // { dg-error "this context" } + return 0; +} + +void g () { + f (S ()); // { dg-error "context|instantiated" } +}