From: Mark Mitchell Date: Wed, 4 Jan 2006 18:48:38 +0000 (+0000) Subject: re PR c++/24782 (wrongly accepted nested private typedef) X-Git-Tag: releases/gcc-4.2.0~5038 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19e65f304be3330abb3f034ffdafd48a78f85f43;p=thirdparty%2Fgcc.git re PR c++/24782 (wrongly accepted nested private typedef) PR c++/24782 * 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. From-SVN: r109342 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1dbf6004e9a4..4487eba9c591 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2006-01-04 Mark Mitchell + + PR c++/24782 + * parser.c (cp_parser_nested_name_specifier_opt): Preserve access + checks, even when parsing tentatively. + 2006-01-04 Richard Henderson Merge from gomp branch. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 86763eb42bdf..13aa29a08559 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 07b9a0df5f73..6ec417fb7df4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-01-04 Mark Mitchell + + PR c++/24782 + * g++.dg/parse/access9.C: New test. + * g++.dg/tc1/dr52.C: Tweak error markers. + 2006-01-04 Richard Henderson 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 index 000000000000..2c29016b0479 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/access9.C @@ -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" } diff --git a/gcc/testsuite/g++.dg/tc1/dr52.C b/gcc/testsuite/g++.dg/tc1/dr52.C index b0896d73fa70..4f4015dc958d 100644 --- a/gcc/testsuite/g++.dg/tc1/dr52.C +++ b/gcc/testsuite/g++.dg/tc1/dr52.C @@ -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" } } };