parser.c (cp_parser_explicit_instantiation): Restore old access before template insta...
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
Sun, 25 May 2003 12:59:22 +0000 (12:59 +0000)
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>
Sun, 25 May 2003 12:59:22 +0000 (12:59 +0000)
* 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
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/access11.C [new file with mode: 0644]

index 98f4f7143bcf3e87ea44e63470e56a99e55931d0..33fcb14d652d690c24d89aff6a2c780955bf8835 100644 (file)
@@ -1,3 +1,8 @@
+2003-05-25  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       * parser.c (cp_parser_explicit_instantiation): Restore old
+       access before template instantiation.
+
 2003-05-23  Geoffrey Keating  <geoffk@apple.com>
 
        * lang-specs.h: Use -o to specify preprocessor's output file.
index cf768e0ac8db68ba99a5edaa9850e1a7c202b4ba..19172f00ea2d19c51e8e3e4c12da3cf8d55acb14 100644 (file)
@@ -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);
 }
index 37b37b4549bff9a7051e0b8811be68da0d7852f6..b670e7d8f71e1b02d0e7f22454df7cb5a32ae84e 100644 (file)
@@ -1,3 +1,7 @@
+2003-05-25  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       * g++.dg/template/access11.C: New test.
+
 2003-05-25  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        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 (file)
index 0000000..f061f66
--- /dev/null
@@ -0,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" }