diff mbox

[C++] Spell correction tweak

Message ID 66e2ea35-56d4-2505-17ba-9239ac145b27@acm.org
State New
Headers show

Commit Message

Nathan Sidwell June 6, 2017, 11 p.m. UTC
Spelling correction blew up for me on the modules branch because 
suggest_alternatives_for was using the raw namespace accessor.  That led 
me to reconsider the behaviour.   This patch implements qualified name 
lookup (which it used to do), but ignoring using directives (which is 
new).  That way we'll see inline namespaces at the same time as their 
parent.  Which also means we shouldn't walk them in their own right. 
This also means we won't count them as part of the walking limit.

As inline-namespaces are intended as an implementation detail that the 
user doesn't care about, I think this is a better behaviour.

Committed to trunk.

nathan
diff mbox

Patch

2017-06-06  Nathan Sidwell  <nathan@acm.org>

	* name-lookup.c (suggest_alternatives_for): Use qualified lookup
	sans using directives.  Don't walk into inline namespaces.

	* g++.dg/pr45330.C: Add inline namespace case.

Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c	(revision 248928)
+++ cp/name-lookup.c	(working copy)
@@ -4714,9 +4714,10 @@  suggest_alternatives_for (location_t loc
   for (unsigned ix = 0; ix != worklist.length (); ix++)
     {
       tree ns = worklist[ix];
+      name_lookup lookup (name);
 
-      if (tree value = ovl_skip_hidden (find_namespace_value (ns, name)))
-	candidates.safe_push (value);
+      if (lookup.search_qualified (ns, false))
+	candidates.safe_push (lookup.value);
 
       if (!limited)
 	{
@@ -4728,7 +4729,8 @@  suggest_alternatives_for (location_t loc
 	  for (tree decl = NAMESPACE_LEVEL (ns)->names;
 	       decl; decl = TREE_CHAIN (decl))
 	    if (TREE_CODE (decl) == NAMESPACE_DECL
-		&& !DECL_NAMESPACE_ALIAS (decl))
+		&& !DECL_NAMESPACE_ALIAS (decl)
+		&& !DECL_NAMESPACE_INLINE_P (decl))
 	      children.safe_push (decl);
 
 	  while (!limited && !children.is_empty ())
Index: testsuite/g++.dg/pr45330.C
===================================================================
--- testsuite/g++.dg/pr45330.C	(revision 248928)
+++ testsuite/g++.dg/pr45330.C	(working copy)
@@ -1,4 +1,4 @@ 
-// { dg-do compile }
+// { dg-do compile { target c++11 } }
 // Search std, __cxxabiv1, and global namespaces, plus two more,
 // breadth first
 
@@ -17,7 +17,10 @@  namespace A
 
 namespace B
 {
-  int foo;			// { dg-message "B::foo" "suggested alternative" }
+  inline namespace I
+  {
+    int foo;			// { dg-message "B::I::foo" "suggested alternative" }
+  }
 }
 
 namespace C