diff mbox series

[C++] Simplify class member lookup

Message ID 41092b53-25b2-ca9e-288a-9d683e3e670b@acm.org
State New
Headers show
Series [C++] Simplify class member lookup | expand

Commit Message

Nathan Sidwell May 1, 2019, 11:35 a.m. UTC
Here's another simplification I'd accumulated.  The final arg to 
get_class_binding no longer needs to be tri-valued, a simple bool will 
do.  This results in better diagnostics in one testcase.

nathan
diff mbox series

Patch

2019-05-01  Nathan Sidwell  <nathan@acm.org>

	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.

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 270764)
+++ gcc/cp/decl.c	(working copy)
@@ -5968,12 +5968,12 @@  reshape_init_class (tree type, reshape_i
 		  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)
Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c	(revision 270764)
+++ gcc/cp/name-lookup.c	(working copy)
@@ -1217,7 +1217,7 @@  search_anon_aggr (tree anon, tree name,
    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, tr
       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, tr
    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
 	}
     }
 
-  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
Index: gcc/cp/name-lookup.h
===================================================================
--- gcc/cp/name-lookup.h	(revision 270764)
+++ gcc/cp/name-lookup.h	(working copy)
@@ -303,8 +303,8 @@  extern void do_namespace_alias (tree, tr
 extern tree do_class_using_decl (tree, tree);
 extern tree lookup_arg_dependent (tree, tree, vec<tree, va_gc> *);
 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 *,
Index: gcc/testsuite/g++.dg/cpp0x/decltype9.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/decltype9.C	(revision 270764)
+++ gcc/testsuite/g++.dg/cpp0x/decltype9.C	(working copy)
@@ -2,8 +2,7 @@ 
 // { dg-do compile { target c++11 } }
 
 template<int> struct A { // { dg-message "defined here" }
-  static int i;
+  static int i; // { dg-message "candidate" }
 };
 
 template<int N> int A<N>::i(decltype (A::i));	// { dg-error "no declaration" }
-// { dg-message "no functions" "note" { target *-*-* } .-1 }