2017-05-16  Nathan Sidwell  <nathan@acm.org>

	* cp-tree.h (OVL_FIRST, OVL_NAME): New.
	(ovl_first): New.
	* constexpr.c (function_concept_check): Use OVL_FIRST.
	* cvt.c (build_expr_type_conversion): Likewise.
	* decl.c (poplevel, grokdeclarator): Use OVL_NAME.
	* decl2.c (mark_used): Use OVL_FIRST.
	* error.c (dump_decl): Use OVL_FIRST, OVL_NAME.
	(dump_expr, location_of): Use OVL_FIRST.
	* friend.c (do_friend): Use OVL_NAME.
	* init.c (build_offset_ref): Use OVL_FIRST.
	* mangle.c (write_member_name): Likewise.
	(write_expression): Use OVL_NAME.
	* method.c (strip_inheriting_ctors): Use OVL_FIRST.
	* name-lookup.c (pushdecl_class_level): Use OVL_NAME.
	* pt.c (check_explicit_specialization): Use OVL_FIRST.
	(check_template_shadow): Likewise.
	(tsubst_template_args): Use OVL_NAME.
	(tsubst_baselink): Use OVL_FIRST.
	* semantics.c (perform_koenig_lookup): Use OVL_NAME.
	* tree.c (get_first_fn): Use OVL_FIRST.
	* typeck.c (finish_class_member_access_expr): Use OVL_NAME.
	(cp_build_addr_expr_1): Use OVL_FIRST.

Index: constraint.cc
===================================================================
--- constraint.cc	(revision 248095)
+++ constraint.cc	(working copy)
@@ -117,10 +117,9 @@ function_concept_check_p (tree t)
   gcc_assert (TREE_CODE (t) == CALL_EXPR);
   tree fn = CALL_EXPR_FN (t);
   if (fn != NULL_TREE
-      && TREE_CODE (fn) == TEMPLATE_ID_EXPR
-      && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
+      && TREE_CODE (fn) == TEMPLATE_ID_EXPR)
     {
-      tree f1 = get_first_fn (fn);
+      tree f1 = OVL_FIRST (TREE_OPERAND (fn, 0));
       if (TREE_CODE (f1) == TEMPLATE_DECL
 	  && DECL_DECLARED_CONCEPT_P (DECL_TEMPLATE_RESULT (f1)))
         return true;
Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 248095)
+++ cp-tree.h	(working copy)
@@ -626,6 +626,11 @@ typedef struct ptrmem_cst * ptrmem_cst_t
    and can be freed afterward.  */
 #define OVL_ARG_DEPENDENT(NODE) TREE_LANG_FLAG_0 (OVERLOAD_CHECK (NODE))
 
+/* The first decl of an overload.  */
+#define OVL_FIRST(NODE)	ovl_first (NODE)
+/* The name of the overload set.  */
+#define OVL_NAME(NODE) DECL_NAME (OVL_FIRST (NODE))
+
 struct GTY(()) tree_overload {
   struct tree_common common;
   tree function;
@@ -6668,6 +6673,13 @@ extern tree hash_tree_cons			(tree, tree
 extern tree hash_tree_chain			(tree, tree);
 extern tree build_qualified_name		(tree, tree, tree, bool);
 extern tree build_ref_qualified_type		(tree, cp_ref_qualifier);
+inline tree
+ovl_first (tree node)
+{
+  while (TREE_CODE (node) == OVERLOAD)
+    node = OVL_FUNCTION (node);
+  return node;
+}
 extern int is_overloaded_fn			(tree);
 extern tree dependent_name			(tree);
 extern tree get_fns				(tree);
Index: cvt.c
===================================================================
--- cvt.c	(revision 248095)
+++ cvt.c	(working copy)
@@ -1722,7 +1722,7 @@ build_expr_type_conversion (int desires,
       int win = 0;
       tree candidate;
       tree cand = TREE_VALUE (conv);
-      cand = OVL_CURRENT (cand);
+      cand = OVL_FIRST (cand);
 
       if (winner && winner == cand)
 	continue;
Index: decl.c
===================================================================
--- decl.c	(revision 248095)
+++ decl.c	(working copy)
@@ -683,7 +683,7 @@ poplevel (int keep, int reverse, int fun
   for (link = decls; link; link = TREE_CHAIN (link))
     {
       decl = TREE_CODE (link) == TREE_LIST ? TREE_VALUE (link) : link;
-      tree name = DECL_NAME (OVL_CURRENT (decl));
+      tree name = OVL_NAME (decl);
 
       if (leaving_for_scope && VAR_P (decl)
 	  /* It's hard to make this ARM compatibility hack play nicely with
@@ -10104,10 +10104,7 @@ grokdeclarator (const cp_declarator *dec
 		      if (variable_template_p (dname))
 			dname = DECL_NAME (dname);
 		      else
-		        {
-		          gcc_assert (is_overloaded_fn (dname));
-		          dname = DECL_NAME (get_first_fn (dname));
-		        }
+			dname = OVL_NAME (dname);
 		    }
 		}
 		/* Fall through.  */
Index: decl2.c
===================================================================
--- decl2.c	(revision 248095)
+++ decl2.c	(working copy)
@@ -5029,7 +5029,7 @@ mark_used (tree decl, tsubst_flags_t com
       decl = BASELINK_FUNCTIONS (decl);
       if (really_overloaded_fn (decl))
 	return true;
-      decl = OVL_CURRENT (decl);
+      decl = OVL_FIRST (decl);
     }
 
   /* Set TREE_USED for the benefit of -Wunused.  */
Index: error.c
===================================================================
--- error.c	(revision 248095)
+++ error.c	(working copy)
@@ -1208,7 +1208,7 @@ dump_decl (cxx_pretty_printer *pp, tree
 
       /* If there's only one function, just treat it like an ordinary
 	 FUNCTION_DECL.  */
-      t = OVL_CURRENT (t);
+      t = OVL_FIRST (t);
       /* Fall through.  */
 
     case FUNCTION_DECL:
@@ -1235,10 +1235,8 @@ dump_decl (cxx_pretty_printer *pp, tree
 	tree name = TREE_OPERAND (t, 0);
 	tree args = TREE_OPERAND (t, 1);
 
-	if (is_overloaded_fn (name))
-	  name = get_first_fn (name);
-	if (DECL_P (name))
-	  name = DECL_NAME (name);
+	if (!identifier_p (name))
+	  name = OVL_NAME (name);
 	dump_decl (pp, name, flags);
 	pp_cxx_begin_template_argument_list (pp);
 	if (args == error_mark_node)
@@ -2498,7 +2496,7 @@ dump_expr (cxx_pretty_printer *pp, tree
 	      /* A::f */
 	      dump_expr (pp, t, flags | TFF_EXPR_IN_PARENS);
 	    else if (BASELINK_P (t))
-	      dump_expr (pp, OVL_CURRENT (BASELINK_FUNCTIONS (t)),
+	      dump_expr (pp, OVL_FIRST (BASELINK_FUNCTIONS (t)),
 			 flags | TFF_EXPR_IN_PARENS);
 	    else
 	      dump_decl (pp, t, flags);
@@ -3004,7 +3002,7 @@ location_of (tree t)
 	return input_location;
     }
   else if (TREE_CODE (t) == OVERLOAD)
-    t = OVL_FUNCTION (t);
+    t = OVL_FIRST (t);
 
   if (DECL_P (t))
     return DECL_SOURCE_LOCATION (t);
Index: friend.c
===================================================================
--- friend.c	(revision 248095)
+++ friend.c	(working copy)
@@ -494,8 +494,7 @@ do_friend (tree ctype, tree declarator,
   if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR)
     {
       declarator = TREE_OPERAND (declarator, 0);
-      if (is_overloaded_fn (declarator))
-	declarator = DECL_NAME (get_first_fn (declarator));
+      declarator = OVL_NAME (declarator);
     }
 
   if (ctype)
Index: init.c
===================================================================
--- init.c	(revision 248095)
+++ init.c	(working copy)
@@ -2063,7 +2063,7 @@ build_offset_ref (tree type, tree member
       if (TREE_CODE (t) != TEMPLATE_ID_EXPR && !really_overloaded_fn (t))
 	{
 	  /* Get rid of a potential OVERLOAD around it.  */
-	  t = OVL_CURRENT (t);
+	  t = OVL_FIRST (t);
 
 	  /* Unique functions are handled easily.  */
 
Index: mangle.c
===================================================================
--- mangle.c	(revision 248095)
+++ mangle.c	(working copy)
@@ -2833,8 +2833,7 @@ write_member_name (tree member)
   else if (TREE_CODE (member) == TEMPLATE_ID_EXPR)
     {
       tree name = TREE_OPERAND (member, 0);
-      if (TREE_CODE (name) == OVERLOAD)
-	name = OVL_FUNCTION (name);
+      name = OVL_FIRST (name);
       write_member_name (name);
       write_template_args (TREE_OPERAND (member, 1));
     }
@@ -3053,10 +3052,7 @@ write_expression (tree expr)
   else if (TREE_CODE (expr) == TEMPLATE_ID_EXPR)
     {
       tree fn = TREE_OPERAND (expr, 0);
-      if (is_overloaded_fn (fn))
-	fn = get_first_fn (fn);
-      if (DECL_P (fn))
-	fn = DECL_NAME (fn);
+      fn = OVL_NAME (fn);
       if (IDENTIFIER_OPNAME_P (fn))
 	write_string ("on");
       write_unqualified_id (fn);
@@ -3257,7 +3253,7 @@ write_expression (tree expr)
 	    if ((TREE_CODE (fn) == FUNCTION_DECL
 		 || TREE_CODE (fn) == OVERLOAD)
 		&& type_dependent_expression_p_push (expr))
-	      fn = DECL_NAME (get_first_fn (fn));
+	      fn = OVL_NAME (fn);
 
 	    write_expression (fn);
 	  }
Index: method.c
===================================================================
--- method.c	(revision 248095)
+++ method.c	(working copy)
@@ -502,10 +502,8 @@ strip_inheriting_ctors (tree dfn)
     return dfn;
   tree fn = dfn;
   while (tree inh = DECL_INHERITED_CTOR (fn))
-    {
-      inh = OVL_CURRENT (inh);
-      fn = inh;
-    }
+    fn = OVL_FIRST (inh);
+
   if (TREE_CODE (fn) == TEMPLATE_DECL
       && TREE_CODE (dfn) == FUNCTION_DECL)
     fn = DECL_TEMPLATE_RESULT (fn);
Index: name-lookup.c
===================================================================
--- name-lookup.c	(revision 248095)
+++ name-lookup.c	(working copy)
@@ -3610,7 +3610,6 @@ set_inherited_value_binding_p (cxx_bindi
 bool
 pushdecl_class_level (tree x)
 {
-  tree name;
   bool is_valid = true;
   bool subtime;
 
@@ -3621,10 +3620,7 @@ pushdecl_class_level (tree x)
 
   subtime = timevar_cond_start (TV_NAME_LOOKUP);
   /* Get the name of X.  */
-  if (TREE_CODE (x) == OVERLOAD)
-    name = DECL_NAME (get_first_fn (x));
-  else
-    name = DECL_NAME (x);
+  tree name = OVL_NAME (x);
 
   if (name)
     {
Index: pt.c
===================================================================
--- pt.c	(revision 248095)
+++ pt.c	(working copy)
@@ -2930,7 +2930,7 @@ check_explicit_specialization (tree decl
 		     methods->iterate (idx, &ovl);
 		     ++idx)
 		  {
-		    if (!DECL_CONV_FN_P (OVL_CURRENT (ovl)))
+		    if (!DECL_CONV_FN_P (OVL_FIRST (ovl)))
 		      /* There are no more conversion functions.  */
 		      break;
 
@@ -3910,8 +3910,7 @@ check_template_shadow (tree decl)
     return true;
 
   /* Figure out what we're shadowing.  */
-  if (TREE_CODE (decl) == OVERLOAD)
-    decl = OVL_CURRENT (decl);
+  decl = OVL_FIRST (decl);
   olddecl = innermost_non_namespace_value (DECL_NAME (decl));
 
   /* If there's no previous binding for this name, we're not shadowing
@@ -14128,7 +14127,7 @@ tsubst_baselink (tree baselink, tree obj
 	  template_args = tsubst_template_args (template_args, args,
 						complain, in_decl);
       }
-    name = DECL_NAME (get_first_fn (fns));
+    name = OVL_NAME (fns);
     if (IDENTIFIER_TYPENAME_P (name))
       name = mangle_conv_op_name_for_type (optype);
     baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1);
@@ -14150,7 +14149,7 @@ tsubst_baselink (tree baselink, tree obj
     if (BASELINK_P (baselink))
       fns = BASELINK_FUNCTIONS (baselink);
     if (!template_id_p && !really_overloaded_fn (fns)
-	&& !mark_used (OVL_CURRENT (fns), complain) && !(complain & tf_error))
+	&& !mark_used (OVL_FIRST (fns), complain) && !(complain & tf_error))
       return error_mark_node;
 
     /* Add back the template arguments, if present.  */
Index: semantics.c
===================================================================
--- semantics.c	(revision 248095)
+++ semantics.c	(working copy)
@@ -2231,15 +2231,10 @@ perform_koenig_lookup (cp_expr fn, vec<t
   /* Find the name of the overloaded function.  */
   if (identifier_p (fn))
     identifier = fn;
-  else if (is_overloaded_fn (fn))
+  else
     {
       functions = fn;
-      identifier = DECL_NAME (get_first_fn (functions));
-    }
-  else if (DECL_P (fn))
-    {
-      functions = fn;
-      identifier = DECL_NAME (fn);
+      identifier = OVL_NAME (functions);
     }
 
   /* A call to a namespace-scope function using an unqualified name.
Index: tree.c
===================================================================
--- tree.c	(revision 248095)
+++ tree.c	(working copy)
@@ -2164,7 +2164,7 @@ get_fns (tree from)
 tree
 get_first_fn (tree from)
 {
-  return OVL_CURRENT (get_fns (from));
+  return OVL_FIRST (get_fns (from));
 }
 
 /* Return a new OVL node, concatenating it with the old one.  */
Index: typeck.c
===================================================================
--- typeck.c	(revision 248095)
+++ typeck.c	(working copy)
@@ -2764,10 +2764,8 @@ finish_class_member_access_expr (cp_expr
 	  template_args = TREE_OPERAND (name, 1);
 	  name = TREE_OPERAND (name, 0);
 
-	  if (TREE_CODE (name) == OVERLOAD)
-	    name = DECL_NAME (get_first_fn (name));
-	  else if (DECL_P (name))
-	    name = DECL_NAME (name);
+	  if (!identifier_p (name))
+	    name = OVL_NAME (name);
 	}
 
       if (scope)
@@ -5746,7 +5744,7 @@ cp_build_addr_expr_1 (tree arg, bool str
       /* Fall through.  */
 
     case OVERLOAD:
-      arg = OVL_CURRENT (arg);
+      arg = OVL_FIRST (arg);
       break;
 
     case OFFSET_REF:
