From b7fc8b576e9aafd37dcc8e78a87372eb8eae011b Mon Sep 17 00:00:00 2001 From: Kriang Lerdsuwanakij Date: Sun, 25 May 2003 12:59:22 +0000 Subject: [PATCH] parser.c (cp_parser_explicit_instantiation): Restore old access before template instantiation. * parser.c (cp_parser_explicit_instantiation): Restore old access before template instantiation. * g++.dg/template/access11.C: New test. From-SVN: r67166 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/parser.c | 8 ++++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/template/access11.C | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/access11.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 98f4f7143bc..33fcb14d652 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2003-05-25 Kriang Lerdsuwanakij + + * parser.c (cp_parser_explicit_instantiation): Restore old + access before template instantiation. + 2003-05-23 Geoffrey Keating * lang-specs.h: Use -o to specify preprocessor's output file. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index cf768e0ac8d..19172f00ea2 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -8318,6 +8318,9 @@ cp_parser_explicit_instantiation (cp_parser* parser) tree type; type = check_tag_decl (decl_specifiers); + /* Turn access control back on for names used during + template instantiation. */ + pop_deferring_access_checks (); if (type) do_type_instantiation (type, extension_specifier, /*complain=*/1); } @@ -8332,13 +8335,14 @@ cp_parser_explicit_instantiation (cp_parser* parser) /*ctor_dtor_or_conv_p=*/NULL); decl = grokdeclarator (declarator, decl_specifiers, NORMAL, 0, NULL); + /* Turn access control back on for names used during + template instantiation. */ + pop_deferring_access_checks (); /* Do the explicit instantiation. */ do_decl_instantiation (decl, extension_specifier); } /* We're done with the instantiation. */ end_explicit_instantiation (); - /* Turn access control back on. */ - pop_deferring_access_checks (); cp_parser_consume_semicolon_at_end_of_statement (parser); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 37b37b4549b..b670e7d8f71 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-05-25 Kriang Lerdsuwanakij + + * g++.dg/template/access11.C: New test. + 2003-05-25 Kriang Lerdsuwanakij PR c++/10849 diff --git a/gcc/testsuite/g++.dg/template/access11.C b/gcc/testsuite/g++.dg/template/access11.C new file mode 100644 index 00000000000..f061f6616eb --- /dev/null +++ b/gcc/testsuite/g++.dg/template/access11.C @@ -0,0 +1,24 @@ +// Copyright (C) 2003 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij +// { dg-do compile } + +// Access checking during explicit instantiation. + +class A { + typedef int X; // { dg-error "private" } +}; + +class X { + private: + template struct Y; +}; + +template <> struct X::Y { + A::X x; // { dg-error "this context" } +}; + +template struct X::Y { + typename T::X x; // { dg-error "this context" } +}; + +template struct X::Y; // { dg-error "instantiated" } -- 2.30.2