Commit 0f2a66c9 by Nathan Sidwell Committed by Nathan Sidwell

friend.c (add_friend): Only perform access checks when context is a class.

	* friend.c (add_friend): Only perform access checks when context
	is a class.
	* lex.c (cxx_make_type): Only create a binfo for aggregate types.
	* parser.c (cp_parser_class_specifier): Disable access checks here
	when parsing the body of a templated class.
	* semantics.c (perform_or_defer_access_checks): Reorder to allow
	NULL binfos when not checking access.

From-SVN: r83771
parent 58c42dc2
2004-06-28 Nathan Sidwell <nathan@codesourcery.com>
* friend.c (add_friend): Only perform access checks when context
is a class.
* lex.c (cxx_make_type): Only create a binfo for aggregate types.
* parser.c (cp_parser_class_specifier): Disable access checks here
when parsing the body of a templated class.
* semantics.c (perform_or_defer_access_checks): Reorder to allow
NULL binfos when not checking access.
2004-06-28 Nathan Sidwell <nathan@codesourcery.com>
Use vector API for vbase list.
* cp-tree.h: Include vec.h
(DEF_VEC_P (tree)): New type.
......
......@@ -129,6 +129,7 @@ add_friend (tree type, tree decl, bool complain)
tree typedecl;
tree list;
tree name;
tree ctx;
if (decl == error_mark_node)
return;
......@@ -163,12 +164,9 @@ add_friend (tree type, tree decl, bool complain)
list = TREE_CHAIN (list);
}
if (DECL_CLASS_SCOPE_P (decl))
{
tree class_binfo = TYPE_BINFO (DECL_CONTEXT (decl));
if (!uses_template_parms (BINFO_TYPE (class_binfo)))
perform_or_defer_access_check (class_binfo, decl);
}
ctx = DECL_CONTEXT (decl);
if (ctx && CLASS_TYPE_P (ctx) && !uses_template_parms (ctx))
perform_or_defer_access_check (TYPE_BINFO (ctx), decl);
maybe_add_class_template_decl_list (type, decl, /*friend_p=*/1);
......
......@@ -779,6 +779,8 @@ cxx_make_type (enum tree_code code)
presence of parse errors, the normal was of assuring this
might not ever get executed, so we lay it out *immediately*. */
build_pointer_type (t);
TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
}
else
/* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits. But,
......@@ -786,15 +788,6 @@ cxx_make_type (enum tree_code code)
clear it here. */
TYPE_ALIAS_SET (t) = 0;
/* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
since they can be virtual base types, and we then need a
canonical binfo for them. Ideally, this would be done lazily for
all types. */
if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM
|| code == BOUND_TEMPLATE_TEMPLATE_PARM
|| code == TYPENAME_TYPE)
TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
return t;
}
......
......@@ -12342,12 +12342,22 @@ cp_parser_class_specifier (cp_parser* parser)
if (nested_name_specifier_p)
pop_p = push_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (type)));
type = begin_class_definition (type);
if (processing_template_decl)
/* There are no access checks when parsing a template, as we do no
know if a specialization will be a friend. */
push_deferring_access_checks (dk_no_check);
if (type == error_mark_node)
/* If the type is erroneous, skip the entire body of the class. */
cp_parser_skip_to_closing_brace (parser);
else
/* Parse the member-specification. */
cp_parser_member_specification_opt (parser);
if (processing_template_decl)
pop_deferring_access_checks ();
/* Look for the trailing `}'. */
cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
/* We get better error messages by noticing a common problem: a
......
......@@ -257,18 +257,19 @@ perform_or_defer_access_check (tree binfo, tree decl)
{
tree check;
my_friendly_assert (TREE_CODE (binfo) == TREE_VEC, 20030623);
/* Exit if we are in a context that no access checking is performed. */
if (deferred_access_stack->deferring_access_checks_kind == dk_no_check)
return;
my_friendly_assert (TREE_CODE (binfo) == TREE_VEC, 20030623);
/* If we are not supposed to defer access checks, just check now. */
if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred)
{
enforce_access (binfo, decl);
return;
}
/* Exit if we are in a context that no access checking is performed. */
else if (deferred_access_stack->deferring_access_checks_kind == dk_no_check)
return;
/* See if we are already going to perform this check. */
for (check = deferred_access_stack->deferred_access_checks;
check;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment