re PR c++/5655 (Member redeclared within its class definition with a different access specifier is not rejected)

PR c++/5655
	* parser.c (cp_parser_check_access_in_redeclaration): New function.
	(cp_parser_member_declaration): Use it.
	(cp_parser_template_declaration_after_export): Likewise.

	* g++.dg/parse/access7.C: New test.
	* g++.old-deja/g++.brendan/crash56.C: Fix redeclaration error.

From-SVN: r71771
This commit is contained in:
Kriang Lerdsuwanakij 2003-09-25 12:51:39 +00:00 committed by Kriang Lerdsuwanakij
parent 21e69789dd
commit 37d407a1cf
5 changed files with 56 additions and 3 deletions

View File

@ -1,3 +1,10 @@
2003-09-25 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/5655
* parser.c (cp_parser_check_access_in_redeclaration): New function.
(cp_parser_member_declaration): Use it.
(cp_parser_template_declaration_after_export): Likewise.
2003-09-22 Gabriel Dos Reis <gcc@integrable-solutions.net> 2003-09-22 Gabriel Dos Reis <gcc@integrable-solutions.net>
* cp-tree.h (scope_kind): Add new enumerator. * cp-tree.h (scope_kind): Add new enumerator.
@ -706,7 +713,7 @@
(do_friend): Adjust add_friend call. (do_friend): Adjust add_friend call.
* decl.c (grokdeclarator): Adjust make_friend_class call. * decl.c (grokdeclarator): Adjust make_friend_class call.
* parser.c (cp_parser_member_declaration): Likewise. * parser.c (cp_parser_member_declaration): Likewise.
(cp_parser_template_declaration_after_exp): Likewise. (cp_parser_template_declaration_after_export): Likewise.
* pt.c (instantiate_class_template): Adjust make_friend_class * pt.c (instantiate_class_template): Adjust make_friend_class
and add_friend call. and add_friend call.
* cp-tree.h (make_friend_class): Adjust declaration. * cp-tree.h (make_friend_class): Adjust declaration.

View File

@ -1651,6 +1651,8 @@ static enum tag_types cp_parser_token_is_class_key
(cp_token *); (cp_token *);
static void cp_parser_check_class_key static void cp_parser_check_class_key
(enum tag_types, tree type); (enum tag_types, tree type);
static void cp_parser_check_access_in_redeclaration
(tree type);
static bool cp_parser_optional_template_keyword static bool cp_parser_optional_template_keyword
(cp_parser *); (cp_parser *);
static void cp_parser_pre_parsed_nested_name_specifier static void cp_parser_pre_parsed_nested_name_specifier
@ -11870,6 +11872,8 @@ cp_parser_member_declaration (cp_parser* parser)
/* Add it to the class. */ /* Add it to the class. */
finish_member_declaration (decl); finish_member_declaration (decl);
} }
else
cp_parser_check_access_in_redeclaration (TYPE_NAME (type));
} }
} }
else else
@ -13657,7 +13661,12 @@ cp_parser_template_declaration_after_export (cp_parser* parser, bool member_p)
/* If this is a member template declaration, let the front /* If this is a member template declaration, let the front
end know. */ end know. */
if (member_p && !friend_p && decl) if (member_p && !friend_p && decl)
decl = finish_member_template_decl (decl); {
if (TREE_CODE (decl) == TYPE_DECL)
cp_parser_check_access_in_redeclaration (decl);
decl = finish_member_template_decl (decl);
}
else if (friend_p && decl && TREE_CODE (decl) == TYPE_DECL) else if (friend_p && decl && TREE_CODE (decl) == TYPE_DECL)
make_friend_class (current_class_type, TREE_TYPE (decl), make_friend_class (current_class_type, TREE_TYPE (decl),
/*complain=*/true); /*complain=*/true);
@ -14265,6 +14274,23 @@ cp_parser_check_class_key (enum tag_types class_key, tree type)
type); type);
} }
/* Issue an error message if DECL is redeclared with differnt
access than its original declaration [class.access.spec/3].
This applies to nested classes and nested class templates.
[class.mem/1]. */
static void cp_parser_check_access_in_redeclaration (tree decl)
{
if (!CLASS_TYPE_P (TREE_TYPE (decl)))
return;
if ((TREE_PRIVATE (decl)
!= (current_access_specifier == access_private_node))
|| (TREE_PROTECTED (decl)
!= (current_access_specifier == access_protected_node)))
error ("%D redeclared with different access", decl);
}
/* Look for the `template' keyword, as a syntactic disambiguator. /* Look for the `template' keyword, as a syntactic disambiguator.
Return TRUE iff it is present, in which case it will be Return TRUE iff it is present, in which case it will be
consumed. */ consumed. */

View File

@ -1,3 +1,9 @@
2003-09-25 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/5655
* g++.dg/parse/access7.C: New test.
* g++.old-deja/g++.brendan/crash56.C: Fix redeclaration error.
2003-09-24 Ziemowit Laski <zlaski@apple.com> 2003-09-24 Ziemowit Laski <zlaski@apple.com>
MERGE OF objc-improvements-branch into MAINLINE: MERGE OF objc-improvements-branch into MAINLINE:

View File

@ -0,0 +1,13 @@
// { dg-do compile }
// Origin: Paolo Carlini <pcarlini@unitus.it>
// PR c++/5655: Access of member redeclaration.
struct S {
class A;
template <class T> class B;
private:
class A {}; // { dg-error "different access" }
template <class T> class B {}; // { dg-error "different access" }
};

View File

@ -5,6 +5,8 @@
const bool FALSE = 0; const bool FALSE = 0;
const bool TRUE = 1; const bool TRUE = 1;
class ListDProto { class ListDProto {
protected:
class link;
public: public:
ListDProto(); ListDProto();
ListDProto(const ListDProto&); ListDProto(const ListDProto&);
@ -15,7 +17,6 @@ public:
void clear(); void clear();
void remove_head(); void remove_head();
void remove_tail(); void remove_tail();
class link;
class Vix { class Vix {
public: public:
Vix(); Vix();