This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH,committed] Fix access checking in explicit instantiation
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 25 May 2003 20:02:54 +0700 (ICT)
- Subject: [C++ PATCH,committed] Fix access checking in explicit instantiation
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
This patch makes a small tweak to access checking performed
in explicit template instantiations. We only want to
disable checking when parsing the declaration but not inside
the class or function body during template instantiation. So
I move the 'pop_deferring_access_checks' function call
a bit earlier so that we only skip access checking in the
declaration.
Tested on i686-pc-linux-gnu. Applied on trunk as obvious.
--Kriang
2003-05-25 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
* parser.c (cp_parser_explicit_instantiation): Restore old
access before template instantiation.
2003-05-25 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
* g++.dg/template/access11.C: New test.
diff -cprN gcc-main-save/gcc/cp/parser.c gcc-main-new/gcc/cp/parser.c
*** gcc-main-save/gcc/cp/parser.c Sun May 18 16:35:45 2003
--- gcc-main-new/gcc/cp/parser.c Sun May 25 18:10:02 2003
*************** cp_parser_explicit_instantiation (cp_par
*** 8318,8323 ****
--- 8318,8326 ----
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);
}
*************** cp_parser_explicit_instantiation (cp_par
*** 8332,8344 ****
/*ctor_dtor_or_conv_p=*/NULL);
decl = grokdeclarator (declarator, decl_specifiers,
NORMAL, 0, NULL);
/* 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);
}
--- 8335,8348 ----
/*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 ();
cp_parser_consume_semicolon_at_end_of_statement (parser);
}
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/access11.C gcc-main-new/gcc/testsuite/g++.dg/template/access11.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/access11.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/access11.C Sun May 25 18:14:22 2003
***************
*** 0 ****
--- 1,24 ----
+ // Copyright (C) 2003 Free Software Foundation
+ // Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+ // { dg-do compile }
+
+ // Access checking during explicit instantiation.
+
+ class A {
+ typedef int X; // { dg-error "private" }
+ };
+
+ class X {
+ private:
+ template <typename T> struct Y;
+ };
+
+ template <> struct X::Y<int> {
+ A::X x; // { dg-error "this context" }
+ };
+
+ template <typename T> struct X::Y {
+ typename T::X x; // { dg-error "this context" }
+ };
+
+ template struct X::Y<A>; // { dg-error "instantiated" }