[PATCH] D22127: [include-fixer] Don't add qualifiers to symbols which have global scope operator.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 8 02:46:48 PDT 2016


hokein created this revision.
hokein added a reviewer: bkramer.
hokein added a subscriber: cfe-commits.

http://reviews.llvm.org/D22127

Files:
  include-fixer/IncludeFixerContext.h
  unittests/include-fixer/IncludeFixerTest.cpp

Index: unittests/include-fixer/IncludeFixerTest.cpp
===================================================================
--- unittests/include-fixer/IncludeFixerTest.cpp
+++ unittests/include-fixer/IncludeFixerTest.cpp
@@ -242,18 +242,18 @@
   EXPECT_EQ("#include \"bar.h\"\nnamespace a {\nb::bar::t b;\n}\n",
             runIncludeFixer("namespace a {\nbar::t b;\n}\n"));
 
-  EXPECT_EQ(
-      "#include \"color.h\"\nint test = a::b::Green;\n",
-      runIncludeFixer("int test = Green;\n"));
+  EXPECT_EQ("#include \"color.h\"\nint test = a::b::Green;\n",
+            runIncludeFixer("int test = Green;\n"));
   EXPECT_EQ("#include \"color.h\"\nnamespace d {\nint test = a::b::Green;\n}\n",
             runIncludeFixer("namespace d {\nint test = Green;\n}\n"));
   EXPECT_EQ("#include \"color.h\"\nnamespace a {\nint test = b::Green;\n}\n",
             runIncludeFixer("namespace a {\nint test = Green;\n}\n"));
 
-  // FIXME: Fix-namespace should not fix the global qualified identifier.
-  EXPECT_EQ(
-      "#include \"bar.h\"\na::b::bar b;\n",
-      runIncludeFixer("::a::b::bar b;\n"));
+  // Test global scope operator.
+  EXPECT_EQ("#include \"bar.h\"\n::a::b::bar b;\n",
+            runIncludeFixer("::a::b::bar b;\n"));
+  EXPECT_EQ("#include \"bar.h\"\nnamespace a {\n::a::b::bar b;\n}\n",
+            runIncludeFixer("namespace a {\n::a::b::bar b;\n}\n"));
 }
 
 } // namespace
Index: include-fixer/IncludeFixerContext.h
===================================================================
--- include-fixer/IncludeFixerContext.h
+++ include-fixer/IncludeFixerContext.h
@@ -44,6 +44,10 @@
   tooling::Replacement createSymbolReplacement(llvm::StringRef FilePath,
                                                size_t Idx = 0) {
     assert(Idx < MatchedSymbols.size());
+    // No need to add missing qualifiers if SymbolIndentifer has a global scope
+    // operator "::".
+    if (getSymbolIdentifier().startswith("::"))
+      return tooling::Replacement();
     std::string QualifiedName = MatchedSymbols[Idx].getQualifiedName();
     // For nested classes, the qualified name constructed from database misses
     // some stripped qualifiers, because when we search a symbol in database,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22127.63191.patch
Type: text/x-patch
Size: 2213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160708/a05b2d10/attachment.bin>


More information about the cfe-commits mailing list