This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Spell correction tweak


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
--
Nathan Sidwell
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]