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

	* name-lookup.h (pushdecl): Add default friend parm.
	(pushdecl_maybe_friend): Delete.
	(pushdecl_top_level): Add default friend parm.
	(pushdecl_top_level_maybe_friend): Delete.
	* name-lookup.c (pushdecl_maybe_friend): Delete.
	(pushdecl): Add is_friend parm.
	(pushdecl_top_level): Add is friend_parm.
	(pushdecl_top_level_maybe_friend, pushdecl_top_level_1): Delete.
	(pushdecl_top_level_and_finish): Do pushing and finishing directly.
	* friend.c (do_friend): Adjust.
	* pt.c (tsubst_friend_class): Adjust.

Index: friend.c
===================================================================
--- friend.c	(revision 247916)
+++ friend.c	(working copy)
@@ -620,7 +620,7 @@ do_friend (tree ctype, tree declarator,
 		 declaration, the program is ill-formed.  */
 	      tree t = lookup_name_innermost_nonclass_level (DECL_NAME (decl));
 	      if (t)
-		decl = pushdecl_maybe_friend (decl, /*is_friend=*/true);
+		decl = pushdecl (decl, /*is_friend=*/true);
 	      else
 		{
 		  error ("friend declaration %qD in local class without "
Index: name-lookup.c
===================================================================
--- name-lookup.c	(revision 247916)
+++ name-lookup.c	(working copy)
@@ -1862,10 +1862,11 @@ pushdecl_maybe_friend_1 (tree x, bool is
   return x;
 }
 
-/* Wrapper for pushdecl_maybe_friend_1.  */
+/* Record a decl-node X as belonging to the current lexical scope.
+   It's a friend if IS_FRIEND is true.  */
 
 tree
-pushdecl_maybe_friend (tree x, bool is_friend)
+pushdecl (tree x, bool is_friend)
 {
   tree ret;
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
@@ -1874,14 +1875,6 @@ pushdecl_maybe_friend (tree x, bool is_f
   return ret;
 }
 
-/* Record a decl-node X as belonging to the current lexical scope.  */
-
-tree
-pushdecl (tree x)
-{
-  return pushdecl_maybe_friend (x, false);
-}
-
 /* Enter DECL into the symbol table, if that's appropriate.  Returns
    DECL, or a modified version thereof.  */
 
@@ -2862,7 +2855,7 @@ pushdecl_with_scope_1 (tree x, cp_bindin
     {
       b = current_binding_level;
       current_binding_level = level;
-      x = pushdecl_maybe_friend (x, is_friend);
+      x = pushdecl (x, is_friend);
       current_binding_level = b;
     }
   current_function_decl = function_decl;
@@ -4548,47 +4541,30 @@ parse_using_directive (tree name_space,
     }
 }
 
-/* Like pushdecl, only it places X in the global scope if appropriate.
-   Calls cp_finish_decl to register the variable, initializing it with
-   *INIT, if INIT is non-NULL.  */
+/* Pushes X into the global namespace.  */
 
-static tree
-pushdecl_top_level_1 (tree x, tree *init, bool is_friend)
+tree
+pushdecl_top_level (tree x, bool is_friend)
 {
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
   push_to_top_level ();
   x = pushdecl_namespace_level (x, is_friend);
-  if (init)
-    cp_finish_decl (x, *init, false, NULL_TREE, 0);
   pop_from_top_level ();
   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
   return x;
 }
 
-/* Like pushdecl, only it places X in the global scope if appropriate.  */
-
-tree
-pushdecl_top_level (tree x)
-{
-  return pushdecl_top_level_1 (x, NULL, false);
-}
-
-/* Like pushdecl_top_level, but adding the IS_FRIEND parameter.  */
-
-tree
-pushdecl_top_level_maybe_friend (tree x, bool is_friend)
-{
-  return pushdecl_top_level_1 (x, NULL, is_friend);
-}
-
-/* Like pushdecl, only it places X in the global scope if
-   appropriate.  Calls cp_finish_decl to register the variable,
-   initializing it with INIT.  */
+/* Pushes X into the global namespace and Calls cp_finish_decl to
+   register the variable, initializing it with INIT.  */
 
 tree
 pushdecl_top_level_and_finish (tree x, tree init)
 {
-  return pushdecl_top_level_1 (x, &init, false);
+  push_to_top_level ();
+  x = pushdecl_namespace_level (x, false);
+  cp_finish_decl (x, init, false, NULL_TREE, 0);
+  pop_from_top_level ();
+  return x;
 }
 
 /* Combines two sets of overloaded functions into an OVERLOAD chain, removing
Index: name-lookup.h
===================================================================
--- name-lookup.h	(revision 247916)
+++ name-lookup.h	(working copy)
@@ -335,11 +335,9 @@ extern tree innermost_non_namespace_valu
 extern cxx_binding *outer_binding (tree, cxx_binding *, bool);
 extern void cp_emit_debug_info_for_using (tree, tree);
 
-extern tree pushdecl_maybe_friend (tree, bool is_friend);
-extern tree pushdecl (tree);
 extern tree pushdecl_outermost_localscope (tree);
-extern tree pushdecl_top_level_maybe_friend (tree, bool is_friend);
-extern tree pushdecl_top_level (tree);
+extern tree pushdecl (tree, bool is_friend = false);
+extern tree pushdecl_top_level (tree, bool is_friend = false);
 extern tree pushdecl_top_level_and_finish (tree, tree);
 extern tree pushtag (tree, tree, tag_scope);
 extern bool push_namespace (tree);
Index: pt.c
===================================================================
--- pt.c	(revision 247916)
+++ pt.c	(working copy)
@@ -9920,7 +9920,7 @@ tsubst_friend_class (tree friend_tmpl, t
 	= INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (TREE_TYPE (tmpl)));
 
       /* Inject this template into the global scope.  */
-      friend_type = TREE_TYPE (pushdecl_top_level_maybe_friend (tmpl, true));
+      friend_type = TREE_TYPE (pushdecl_top_level (tmpl, true));
     }
 
   if (context != global_namespace)
