From 0f2a66c9c7ea9602a19ce1fa4a067c1c43e65363 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 28 Jun 2004 10:41:19 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/friend.c | 10 ++++------ gcc/cp/lex.c | 11 ++--------- gcc/cp/parser.c | 10 ++++++++++ gcc/cp/semantics.c | 11 ++++++----- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 14527cadeb6..500567b8896 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2004-06-28 Nathan Sidwell + + * 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 Use vector API for vbase list. diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c index faf558c4245..75551a9678e 100644 --- a/gcc/cp/friend.c +++ b/gcc/cp/friend.c @@ -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); diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index c9422696f4b..1daa1fc6ec9 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -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; } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 56605de72de..10238c4a2f1 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index b4894607201..66c892b7d09 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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; -- 2.30.2