OSDN Git Service

PR c++/24782
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Jan 2006 18:48:38 +0000 (18:48 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Jan 2006 18:48:38 +0000 (18:48 +0000)
* parser.c (cp_parser_nested_name_specifier_opt): Preserve access
checks, even when parsing tentatively.
PR c++/24782
* g++.dg/parse/access9.C: New test.
* g++.dg/tc1/dr52.C: Tweak error markers.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@109342 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/access9.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tc1/dr52.C

index 1dbf600..4487eba 100644 (file)
@@ -1,3 +1,9 @@
+2006-01-04  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/24782
+       * parser.c (cp_parser_nested_name_specifier_opt): Preserve access
+       checks, even when parsing tentatively.
+
 2006-01-04  Richard Henderson  <rth@redhat.com>
 
        Merge from gomp branch.
index 86763eb..13aa29a 100644 (file)
@@ -3517,7 +3517,6 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
                                     bool is_declaration)
 {
   bool success = false;
-  tree access_check = NULL_TREE;
   cp_token_position start = 0;
   cp_token *token;
 
@@ -3537,9 +3536,10 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
 
   /* Remember where the nested-name-specifier starts.  */
   if (cp_parser_uncommitted_to_tentative_parse_p (parser))
-    start = cp_lexer_token_position (parser->lexer, false);
-
-  push_deferring_access_checks (dk_deferred);
+    {
+      start = cp_lexer_token_position (parser->lexer, false);
+      push_deferring_access_checks (dk_deferred);
+    }
 
   while (true)
     {
@@ -3718,10 +3718,6 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
       parser->scope = new_scope;
     }
 
-  /* Retrieve any deferred checks.  Do not pop this access checks yet
-     so the memory will not be reclaimed during token replacing below.  */
-  access_check = get_deferred_access_checks ();
-
   /* If parsing tentatively, replace the sequence of tokens that makes
      up the nested-name-specifier with a CPP_NESTED_NAME_SPECIFIER
      token.  That way, should we re-parse the token stream, we will
@@ -3729,19 +3725,27 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
      we issue duplicate error messages.  */
   if (success && start)
     {
-      cp_token *token = cp_lexer_token_at (parser->lexer, start);
+      cp_token *token;
+      tree access_checks;
 
+      token = cp_lexer_token_at (parser->lexer, start);
       /* Reset the contents of the START token.  */
       token->type = CPP_NESTED_NAME_SPECIFIER;
-      token->value = build_tree_list (access_check, parser->scope);
+      /* Retrieve any deferred checks.  Do not pop this access checks yet
+        so the memory will not be reclaimed during token replacing below.  */
+      access_checks = get_deferred_access_checks ();
+      token->value = build_tree_list (copy_list (access_checks),
+                                     parser->scope);
       TREE_TYPE (token->value) = parser->qualifying_scope;
       token->keyword = RID_MAX;
 
       /* Purge all subsequent tokens.  */
       cp_lexer_purge_tokens_after (parser->lexer, start);
     }
+  
+  if (start)
+    pop_to_parent_deferring_access_checks ();
 
-  pop_deferring_access_checks ();
   return success ? parser->scope : NULL_TREE;
 }
 
index 07b9a0d..6ec417f 100644 (file)
@@ -1,3 +1,9 @@
+2006-01-04  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/24782
+       * g++.dg/parse/access9.C: New test.
+       * g++.dg/tc1/dr52.C: Tweak error markers.
+
 2006-01-04  Richard Henderson  <rth@redhat.com>
 
        Merge from gomp branch.
diff --git a/gcc/testsuite/g++.dg/parse/access9.C b/gcc/testsuite/g++.dg/parse/access9.C
new file mode 100644 (file)
index 0000000..2c29016
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/24782
+
+class Foo { public:  typedef int type1; };
+class Bar { private: typedef Foo type2; }; // { dg-error "private" } 
+void g(Bar::type2::type1) {} // { dg-error "context" }
index b0896d7..4f4015d 100644 (file)
@@ -17,7 +17,7 @@ struct B1 : B {};
 struct B2 : B {};
 
 struct C
-{
+{ // { dg-error "C" }
   void foo(void);
 };
 
@@ -29,6 +29,6 @@ public:
   void bar(void)
   {
     this->B::foo();  // { dg-error "" }
-    this->C::foo();  // { dg-error "" }
+    this->C::foo();  // { dg-error "inaccessible|context" }
   }
 };