From 7a4e1f7d634faf92e10cf1b42ef162187ddb5f70 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 31 Aug 2018 12:38:00 +0000 Subject: [PATCH] [PR c++/87155] Anonymous namespace and https://gcc.gnu.org/ml/gcc-patches/2018-08/msg02031.html PR c++/87155 PR c++/84707 cp/ * name-lookup.c (name_lookup::search_namespace): Don't look at inlines when searching for NULL names. testsuite/ * g++.dg/cpp0x/pr87155.C: New. * g++.dg/cpp0x/inline-ns10.C: Adjust. From-SVN: r264016 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/name-lookup.c | 13 ++++++++----- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/g++.dg/cpp0x/inline-ns10.C | 7 +++++-- gcc/testsuite/g++.dg/cpp0x/pr87155.C | 14 ++++++++++++++ 5 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr87155.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0c5a4bf71c5..9e135b34535 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2018-08-31 Nathan Sidwell + PR c++/87155 + PR c++/84707 + * name-lookup.c (name_lookup::search_namespace): Don't look at + inlines when searching for NULL names. + * decl.c (decls_match): Remove SYSTEM_IMPLICIT_EXTERN_C matching of return types and parms. * parser.c (cp_parser_parameter_declaration_clause): Likewise, diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index c0a12d74634..bb0a70e1877 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -558,11 +558,14 @@ name_lookup::search_namespace (tree scope) /* Look in exactly namespace. */ bool found = search_namespace_only (scope); - - /* Recursively look in its inline children. */ - if (vec *inlinees = DECL_NAMESPACE_INLINEES (scope)) - for (unsigned ix = inlinees->length (); ix--;) - found |= search_namespace ((*inlinees)[ix]); + + /* Don't look into inline children, if we're looking for an + anonymous name -- it must be in the current scope, if anywhere. */ + if (name) + /* Recursively look in its inline children. */ + if (vec *inlinees = DECL_NAMESPACE_INLINEES (scope)) + for (unsigned ix = inlinees->length (); ix--;) + found |= search_namespace ((*inlinees)[ix]); if (found) mark_found (scope); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ac3722a58eb..a588e18871b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-08-31 Nathan Sidwell + + PR c++/87155 + PR c++/84707 + * g++.dg/cpp0x/pr87155.C: New. + * g++.dg/cpp0x/inline-ns10.C: Adjust. + 2018-08-31 Jakub Jelinek PR middle-end/87138 diff --git a/gcc/testsuite/g++.dg/cpp0x/inline-ns10.C b/gcc/testsuite/g++.dg/cpp0x/inline-ns10.C index 3ab425f7be4..68e8034d4fd 100644 --- a/gcc/testsuite/g++.dg/cpp0x/inline-ns10.C +++ b/gcc/testsuite/g++.dg/cpp0x/inline-ns10.C @@ -2,7 +2,10 @@ // { dg-do compile { target c++11 } } inline namespace { - namespace {} + namespace {} // not this one + void a (); } -namespace {} // { dg-error "conflicts" } +namespace { + int a (); // { dg-error "ambiguating" "" } +} diff --git a/gcc/testsuite/g++.dg/cpp0x/pr87155.C b/gcc/testsuite/g++.dg/cpp0x/pr87155.C new file mode 100644 index 00000000000..7c7e8fbfee6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr87155.C @@ -0,0 +1,14 @@ +// { dg-do compile { target c++11 } } +// PR c++/87155 confused about which anon namespace + +namespace { + void a (); // this one +} + +inline namespace n2 { + namespace {} +} + +namespace { + int a (); // { dg-error "ambiguating" "" } +} -- 2.30.2