+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>
* cp-tree.h (scope_kind): Add new enumerator.
(do_friend): Adjust add_friend call.
* decl.c (grokdeclarator): Adjust make_friend_class call.
* 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
and add_friend call.
* cp-tree.h (make_friend_class): Adjust declaration.
(cp_token *);
static void cp_parser_check_class_key
(enum tag_types, tree type);
+static void cp_parser_check_access_in_redeclaration
+ (tree type);
static bool cp_parser_optional_template_keyword
(cp_parser *);
static void cp_parser_pre_parsed_nested_name_specifier
/* Add it to the class. */
finish_member_declaration (decl);
}
+ else
+ cp_parser_check_access_in_redeclaration (TYPE_NAME (type));
}
}
else
/* If this is a member template declaration, let the front
end know. */
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)
make_friend_class (current_class_type, TREE_TYPE (decl),
/*complain=*/true);
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.
Return TRUE iff it is present, in which case it will be
consumed. */