From 9a54a0d916273cf9b1be93ee5b9bed207bd3ef40 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 1 May 2019 11:38:54 +0000 Subject: [PATCH] [C++ PATCH] Simplify class member lookup https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00004.html gcc/cp/ * name-lookup.h (get_class_binding_direct): Change final arg to bool. (get_class_binding): Likewise. * name-lookup.c (get_class_binding_direct): Replace TYPE_OR_FNS arg with WANT_TYPE bool. Simplify. (get_class_binding): Adjust final arg. * decl.c (reshape_init_class): Adjust get_class_binding calls. gcc/testsuite/ * g++.dg/cpp0x/decltype9.C: Adjust expected diagnostics. From-SVN: r270765 --- gcc/cp/ChangeLog | 10 ++++++++ gcc/cp/decl.c | 4 +-- gcc/cp/name-lookup.c | 35 +++++++++++--------------- gcc/cp/name-lookup.h | 4 +-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/g++.dg/cpp0x/decltype9.C | 3 +-- 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ec15854d22d..3213b4aa2df 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2019-05-01 Nathan Sidwell + + * name-lookup.h (get_class_binding_direct): Change final arg to + bool. + (get_class_binding): Likewise. + * name-lookup.c (get_class_binding_direct): Replace TYPE_OR_FNS + arg with WANT_TYPE bool. Simplify. + (get_class_binding): Adjust final arg. + * decl.c (reshape_init_class): Adjust get_class_binding calls. + 2019-04-30 Nathan Sidwell * cp-objcp-common.c (cp_common_init_ts): Use MARK_TS_EXP for _EXPR diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5c4a38e7980..ee38ac25e65 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5968,12 +5968,12 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p, tree id = DECL_NAME (d->cur->index); gcc_assert (id); gcc_checking_assert (d->cur->index - == get_class_binding (type, id, false)); + == get_class_binding (type, id)); field = d->cur->index; } } else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE) - field = get_class_binding (type, d->cur->index, false); + field = get_class_binding (type, d->cur->index); else { if (complain & tf_error) diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 4ca976c812d..89d85f6c7d7 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1217,7 +1217,7 @@ search_anon_aggr (tree anon, tree name, bool want_type) Use this if you do not want lazy member creation. */ tree -get_class_binding_direct (tree klass, tree name, int type_or_fns) +get_class_binding_direct (tree klass, tree name, bool want_type) { gcc_checking_assert (RECORD_OR_UNION_TYPE_P (klass)); @@ -1233,31 +1233,26 @@ get_class_binding_direct (tree klass, tree name, int type_or_fns) val = member_vec_binary_search (member_vec, lookup); if (!val) ; - else if (type_or_fns > 0) - { - if (STAT_HACK_P (val)) - val = STAT_TYPE (val); - else if (!DECL_DECLARES_TYPE_P (val)) - val = NULL_TREE; - } else if (STAT_HACK_P (val)) - val = STAT_DECL (val); + val = want_type ? STAT_TYPE (val) : STAT_DECL (val); + else if (want_type && !DECL_DECLARES_TYPE_P (val)) + val = NULL_TREE; } else { - if (member_vec && type_or_fns <= 0) + if (member_vec && !want_type) val = member_vec_linear_search (member_vec, lookup); - if (type_or_fns < 0) - /* Don't bother looking for field. We don't want it. */; - else if (!val || (TREE_CODE (val) == OVERLOAD - && OVL_DEDUP_P (val))) + if (!val || (TREE_CODE (val) == OVERLOAD && OVL_DEDUP_P (val))) /* Dependent using declarations are a 'field', make sure we return that even if we saw an overload already. */ - if (tree field_val = fields_linear_search (klass, lookup, - type_or_fns > 0)) - if (!val || TREE_CODE (field_val) == USING_DECL) - val = field_val; + if (tree field_val = fields_linear_search (klass, lookup, want_type)) + { + if (!val) + val = field_val; + else if (TREE_CODE (field_val) == USING_DECL) + val = ovl_make (field_val, val); + } } /* Extract the conversion operators asked for, unless the general @@ -1278,7 +1273,7 @@ get_class_binding_direct (tree klass, tree name, int type_or_fns) special function creation as necessary. */ tree -get_class_binding (tree klass, tree name, int type_or_fns) +get_class_binding (tree klass, tree name, bool want_type) { klass = complete_type (klass); @@ -1308,7 +1303,7 @@ get_class_binding (tree klass, tree name, int type_or_fns) } } - return get_class_binding_direct (klass, name, type_or_fns); + return get_class_binding_direct (klass, name, want_type); } /* Find the slot containing overloads called 'NAME'. If there is no diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index a47486d1b8a..311654af75d 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -303,8 +303,8 @@ extern void do_namespace_alias (tree, tree); extern tree do_class_using_decl (tree, tree); extern tree lookup_arg_dependent (tree, tree, vec *); extern tree search_anon_aggr (tree, tree, bool = false); -extern tree get_class_binding_direct (tree, tree, int type_or_fns = -1); -extern tree get_class_binding (tree, tree, int type_or_fns = -1); +extern tree get_class_binding_direct (tree, tree, bool want_type = false); +extern tree get_class_binding (tree, tree, bool want_type = false); extern tree *find_member_slot (tree klass, tree name); extern tree *add_member_slot (tree klass, tree name); extern void resort_type_member_vec (void *, void *, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2d0240bbc7a..1427a8ee523 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-05-01 Nathan Sidwell + + * g++.dg/cpp0x/decltype9.C: Adjust expected diagnostics. + 2019-04-30 Jakub Jelinek PR target/89093 diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype9.C b/gcc/testsuite/g++.dg/cpp0x/decltype9.C index 45cd9ed7da3..f6cfb0c67c1 100644 --- a/gcc/testsuite/g++.dg/cpp0x/decltype9.C +++ b/gcc/testsuite/g++.dg/cpp0x/decltype9.C @@ -2,8 +2,7 @@ // { dg-do compile { target c++11 } } template struct A { // { dg-message "defined here" } - static int i; + static int i; // { dg-message "candidate" } }; template int A::i(decltype (A::i)); // { dg-error "no declaration" } -// { dg-message "no functions" "note" { target *-*-* } .-1 } -- 2.30.2