public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PR c++/87155] Anonymous namespace and
@ 2018-08-31 12:36 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2018-08-31 12:36 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 915 bytes --]

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

[-- Attachment #2: pr87155.diff --]
[-- Type: text/x-patch, Size: 2213 bytes --]

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" "" }
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-08-31 12:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-31 12:36 [PR c++/87155] Anonymous namespace and Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).