[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-patches
Subject:    [PR c++/87155] Anonymous namespace and
From:       Nathan Sidwell <nathan () acm ! org>
Date:       2018-08-31 12:36:03
Message-ID: d1b15c8e-762e-d9c9-d7f2-e6ca6f60daca () acm ! org
[Download RAW message or body]

This fixes 87155 where an inline namespace caused us to find an inner 
anonymous namespace.

The literal wording of the standard is wrong.  Nobody implements that. 
They implement essentially 1 of 2 different interpretations, which were 
equivalent until inline namespaces and DR2061.  Then one of those 
interpretations has a surprise!

This patch implements the interpretation that gives us the desired 
behaviour.  While we could implement that by giving anonymous namespaces 
names for lookup purposes, that started messing with the debug machinery 
and common core more than desirable.  We can simply not look in inline 
namespaces when searching for a NULL name.

It turns out that 84707 was similar case of this, that we considered ill 
formed (relying on our interpretation of the std).  84707 is well formed 
code.

booted & tested on x86_64-linux, will commit trunk and gcc-8.

nathan

-- 
Nathan Sidwell

["pr87155.diff" (text/x-patch)]

2018-08-31  Nathan Sidwell  <nathan@acm.org>

	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.

Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c	(revision 264014)
+++ gcc/cp/name-lookup.c	(working copy)
@@ -558,11 +558,14 @@ name_lookup::search_namespace (tree scop
 
   /* Look in exactly namespace. */
   bool found = search_namespace_only (scope);
-  
-  /* Recursively look in its inline children.  */
-  if (vec<tree, va_gc> *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<tree, va_gc> *inlinees = DECL_NAMESPACE_INLINEES (scope))
+      for (unsigned ix = inlinees->length (); ix--;)
+	found |= search_namespace ((*inlinees)[ix]);
 
   if (found)
     mark_found (scope);
Index: gcc/testsuite/g++.dg/cpp0x/inline-ns10.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/inline-ns10.C	(revision 264014)
+++ gcc/testsuite/g++.dg/cpp0x/inline-ns10.C	(working copy)
@@ -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" "" }
+}
Index: gcc/testsuite/g++.dg/cpp0x/pr87155.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/pr87155.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/pr87155.C	(working copy)
@@ -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" "" }
+}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic