2019-05-20 Nathan Sidwell gcc/cp/ * name-lookup.c (finish_namespace_using_directive) (finish_local_using_directive): Merge to ... (finish_using_directive): ... here. Handle both contexts. * name-lookup.h (finish_namespace_using_directive) (finish_local_using_directive): Replace with ... (finish_using_directive): ... this. * parser.c (cp_parser_using_directive): Adjust. * pt.c (tsubst_expr): Likewise. libcc1/ * libcp1plugin.cc (plugin_add_using_namespace): Call renamed finish_using_directive. Index: gcc/cp/name-lookup.c =================================================================== --- gcc/cp/name-lookup.c (revision 271416) +++ gcc/cp/name-lookup.c (working copy) @@ -7235,52 +7235,36 @@ emit_debug_info_using_namespace (tree fr } -/* Process a namespace-scope using directive. */ +/* Process a using directive. */ void -finish_namespace_using_directive (tree target, tree attribs) +finish_using_directive (tree target, tree attribs) { - gcc_checking_assert (namespace_bindings_p ()); if (target == error_mark_node) return; - add_using_namespace (current_binding_level->using_directives, - ORIGINAL_NAMESPACE (target)); - emit_debug_info_using_namespace (current_namespace, - ORIGINAL_NAMESPACE (target), false); - - if (attribs == error_mark_node) - return; - - for (tree a = attribs; a; a = TREE_CHAIN (a)) - { - tree name = get_attribute_name (a); - if (is_attribute_p ("strong", name)) - { - warning (0, "strong using directive no longer supported"); - if (CP_DECL_CONTEXT (target) == current_namespace) - inform (DECL_SOURCE_LOCATION (target), - "you may use an inline namespace instead"); - } - else - warning (OPT_Wattributes, "%qD attribute directive ignored", name); - } -} - -/* Process a function-scope using-directive. */ - -void -finish_local_using_directive (tree target, tree attribs) -{ - gcc_checking_assert (local_bindings_p ()); - if (target == error_mark_node) - return; - - if (attribs) - warning (OPT_Wattributes, "attributes ignored on local using directive"); - - add_stmt (build_stmt (input_location, USING_STMT, target)); + if (current_binding_level->kind != sk_namespace) + add_stmt (build_stmt (input_location, USING_STMT, target)); + else + emit_debug_info_using_namespace (current_binding_level->this_entity, + ORIGINAL_NAMESPACE (target), false); add_using_namespace (current_binding_level->using_directives, ORIGINAL_NAMESPACE (target)); + + if (attribs != error_mark_node) + for (tree a = attribs; a; a = TREE_CHAIN (a)) + { + tree name = get_attribute_name (a); + if (current_binding_level->kind == sk_namespace + && is_attribute_p ("strong", name)) + { + warning (0, "strong using directive no longer supported"); + if (CP_DECL_CONTEXT (target) == current_namespace) + inform (DECL_SOURCE_LOCATION (target), + "you may use an inline namespace instead"); + } + else + warning (OPT_Wattributes, "%qD attribute directive ignored", name); + } } Index: gcc/cp/name-lookup.h =================================================================== --- gcc/cp/name-lookup.h (revision 271416) +++ gcc/cp/name-lookup.h (working copy) @@ -1,3 +1,3 @@ -/* Declarations for C++ name lookup routines. +/* Declarations for -*- C++ -*- name lookup routines. Copyright (C) 2003-2019 Free Software Foundation, Inc. Contributed by Gabriel Dos Reis @@ -318,6 +318,5 @@ extern void cp_emit_debug_info_for_using extern void finish_namespace_using_decl (tree, tree, tree); extern void finish_local_using_decl (tree, tree, tree); -extern void finish_namespace_using_directive (tree, tree); -extern void finish_local_using_directive (tree, tree); +extern void finish_using_directive (tree, tree); extern tree pushdecl (tree, bool is_friend = false); extern tree pushdecl_outermost_localscope (tree); Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 271416) +++ gcc/cp/parser.c (working copy) @@ -19738,8 +19738,5 @@ cp_parser_using_directive (cp_parser* pa /* Update the symbol table. */ - if (namespace_bindings_p ()) - finish_namespace_using_directive (namespace_decl, attribs); - else - finish_local_using_directive (namespace_decl, attribs); + finish_using_directive (namespace_decl, attribs); /* Look for the final `;'. */ Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 271416) +++ gcc/cp/pt.c (working copy) @@ -17044,6 +17044,5 @@ tsubst_expr (tree t, tree args, tsubst_f case USING_STMT: - finish_local_using_directive (USING_STMT_NAMESPACE (t), - /*attribs=*/NULL_TREE); + finish_using_directive (USING_STMT_NAMESPACE (t), /*attribs=*/NULL_TREE); break; Index: libcc1/libcp1plugin.cc =================================================================== --- libcc1/libcp1plugin.cc (revision 271416) +++ libcc1/libcp1plugin.cc (working copy) @@ -942,5 +942,5 @@ plugin_add_using_namespace (cc1_plugin:: gcc_assert (TREE_CODE (used_ns) == NAMESPACE_DECL); - finish_namespace_using_directive (used_ns, NULL_TREE); + finish_using_directive (used_ns, NULL_TREE); return 1;