From 0c29f2a2b42a1077975de6417267e138141a02b1 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 5 Sep 2017 20:21:01 +0000 Subject: [PATCH] name-lookup.c (do_class_using_decl): Elide read-once temps. * name-lookup.c (do_class_using_decl): Elide read-once temps. Move declarations to initializations. From-SVN: r251738 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/name-lookup.c | 44 +++++++++++++++----------------------------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 637b7887770..20213890bb2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2017-09-05 Nathan Sidwell + * name-lookup.c (do_class_using_decl): Elide read-once temps. + Move declarations to initializations. + * class.c (add_method): Move slot search and insertion to ... * name-lookup.c (get_method_slot): ... this new function. (lookup_fnfields_slot_nolazy): Cope with NULL slot. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index eacd515ecfb..a9ed429e427 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -4560,20 +4560,6 @@ push_class_level_binding (tree name, tree x) tree do_class_using_decl (tree scope, tree name) { - /* The USING_DECL returned by this function. */ - tree value; - /* The declaration (or declarations) name by this using - declaration. NULL if we are in a template and cannot figure out - what has been named. */ - tree decl; - /* True if SCOPE is a dependent type. */ - bool scope_dependent_p; - /* True if SCOPE::NAME is dependent. */ - bool name_dependent_p; - /* True if any of the bases of CURRENT_CLASS_TYPE are dependent. */ - bool bases_dependent_p; - tree binfo; - if (name == error_mark_node) return NULL_TREE; @@ -4589,6 +4575,7 @@ do_class_using_decl (tree scope, tree name) error ("%<%T::%D%> names destructor", scope, name); return NULL_TREE; } + /* Using T::T declares inheriting ctors, even if T is a typedef. */ if (MAYBE_CLASS_TYPE_P (scope) && (name == TYPE_IDENTIFIER (scope) @@ -4598,6 +4585,8 @@ do_class_using_decl (tree scope, tree name) name = ctor_identifier; CLASSTYPE_NON_AGGREGATE (current_class_type) = true; } + + /* Cannot introduce a constructor name. */ if (constructor_name_p (name, current_class_type)) { error ("%<%T::%D%> names constructor in %qT", @@ -4605,15 +4594,6 @@ do_class_using_decl (tree scope, tree name) return NULL_TREE; } - scope_dependent_p = dependent_scope_p (scope); - name_dependent_p = (scope_dependent_p - || (IDENTIFIER_CONV_OP_P (name) - && dependent_type_p (TREE_TYPE (name)))); - - bases_dependent_p = any_dependent_bases_p (); - - decl = NULL_TREE; - /* From [namespace.udecl]: A using-declaration used as a member-declaration shall refer to a @@ -4624,14 +4604,18 @@ do_class_using_decl (tree scope, tree name) class type. Morover, if SCOPE is dependent, it might match a non-dependent base. */ - if (!scope_dependent_p) + tree decl = NULL_TREE; + if (!dependent_scope_p (scope)) { base_kind b_kind; - binfo = lookup_base (current_class_type, scope, ba_any, &b_kind, - tf_warning_or_error); + tree binfo = lookup_base (current_class_type, scope, ba_any, &b_kind, + tf_warning_or_error); if (b_kind < bk_proper_base) { - if (!bases_dependent_p || b_kind == bk_same_type) + /* If there are dependent bases, scope might resolve at + instantiation time, even if it isn't exactly one of the + dependent bases. */ + if (b_kind == bk_same_type || !any_dependent_bases_p ()) { error_not_base_type (scope, current_class_type); return NULL_TREE; @@ -4642,7 +4626,8 @@ do_class_using_decl (tree scope, tree name) error ("cannot inherit constructors from indirect base %qT", scope); return NULL_TREE; } - else if (!name_dependent_p) + else if (!IDENTIFIER_CONV_OP_P (name) + || !dependent_type_p (TREE_TYPE (name))) { decl = lookup_member (binfo, name, 0, false, tf_warning_or_error); if (!decl) @@ -4651,13 +4636,14 @@ do_class_using_decl (tree scope, tree name) scope); return NULL_TREE; } + /* The binfo from which the functions came does not matter. */ if (BASELINK_P (decl)) decl = BASELINK_FUNCTIONS (decl); } } - value = build_lang_decl (USING_DECL, name, NULL_TREE); + tree value = build_lang_decl (USING_DECL, name, NULL_TREE); USING_DECL_DECLS (value) = decl; USING_DECL_SCOPE (value) = scope; DECL_DEPENDENT_P (value) = !decl; -- 2.30.2