From 6db76e48c18bae5432634a83643542dacf2273e9 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 20 May 2019 13:49:53 +0000 Subject: [PATCH] [C++ PATCH] Commonixe using directive finishing https://gcc.gnu.org/ml/gcc-patches/2019-05/msg01251.html 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. From-SVN: r271420 --- gcc/cp/ChangeLog | 9 ++++++ gcc/cp/name-lookup.c | 62 ++++++++++++++++-------------------------- gcc/cp/name-lookup.h | 5 ++-- gcc/cp/parser.c | 5 +--- gcc/cp/pt.c | 3 +- libcc1/ChangeLog | 5 ++++ libcc1/libcp1plugin.cc | 2 +- 7 files changed, 42 insertions(+), 49 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b9d128434e3..75236fb2968 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,14 @@ 2019-05-20 Nathan Sidwell + * 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. + * cp-tree.h (struct lang_decl_ns): Remove usings field. (DECL_NAMESPACE_USING): Delete. * name-lookup.c (name_lookup::search_usings): Use namespace's diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 58f3265352d..f7952eebe0c 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -7234,54 +7234,38 @@ emit_debug_info_using_namespace (tree from, tree target, bool implicit) implicit); } -/* 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); + } } /* Pushes X into the global namespace. */ diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 311654af75d..aa6180f2d2a 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -1,4 +1,4 @@ -/* 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 @@ -317,8 +317,7 @@ extern void cp_emit_debug_info_for_using (tree, tree); 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); extern tree pushdecl_top_level (tree, bool is_friend = false); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 6705d64389c..b2d6c33300d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19737,10 +19737,7 @@ cp_parser_using_directive (cp_parser* parser) attribs = cp_parser_attributes_opt (parser); /* 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 `;'. */ cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ab79a9e73fa..97d8f08c94d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17043,8 +17043,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, break; 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; case DECL_EXPR: diff --git a/libcc1/ChangeLog b/libcc1/ChangeLog index 0570304b9b7..376e3622410 100644 --- a/libcc1/ChangeLog +++ b/libcc1/ChangeLog @@ -1,3 +1,8 @@ +2019-05-20 Nathan Sidwell + + * libcp1plugin.cc (plugin_add_using_namespace): Call renamed + finish_using_directive. + 2019-01-01 Jakub Jelinek Update copyright years. diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc index 2aab488ba2a..eed94662f85 100644 --- a/libcc1/libcp1plugin.cc +++ b/libcc1/libcp1plugin.cc @@ -941,7 +941,7 @@ plugin_add_using_namespace (cc1_plugin::connection *, 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; } -- 2.30.2