[PATCH] D22812: [include-fixer] Don't add qualifiers in missing complete type cases.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 26 09:40:26 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL276761: [include-fixer] Don't add qualifiers in missing complete type cases. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D22812?vs=65531&id=65544#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22812

Files:
  clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
  clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp

Index: clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
===================================================================
--- clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
+++ clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
@@ -73,6 +73,7 @@
         T.getUnqualifiedType().getAsString(context.getPrintingPolicy());
     DEBUG(llvm::dbgs() << "Query missing complete type '" << QueryString
                        << "'");
+    // Pass an empty range here since we don't add qualifier in this case.
     query(QueryString, "", tooling::Range());
     return false;
   }
@@ -360,9 +361,11 @@
 
   if (AddQualifiers) {
     for (const auto &Info : Context.getQuerySymbolInfos()) {
-      CleanReplaces->insert({FilePath, Info.Range.getOffset(),
-                             Info.Range.getLength(),
-                             Context.getHeaderInfos().front().QualifiedName});
+      // Ignore the empty range.
+      if (Info.Range.getLength() > 0)
+        CleanReplaces->insert({FilePath, Info.Range.getOffset(),
+                               Info.Range.getLength(),
+                               Context.getHeaderInfos().front().QualifiedName});
     }
   }
   return formatReplacements(Code, *CleanReplaces, Style);
Index: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
@@ -335,6 +335,11 @@
   EXPECT_EQ(ExpectedCode, runIncludeFixer(TestCode));
 }
 
+TEST(IncludeFixer, DontAddQualifiersForMissingCompleteType) {
+  EXPECT_EQ("#include \"bar.h\"\nclass bar;\nvoid f() {\nbar* b;\nb->f();\n}",
+            runIncludeFixer("class bar;\nvoid f() {\nbar* b;\nb->f();\n}"));
+}
+
 } // namespace
 } // namespace include_fixer
 } // namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22812.65544.patch
Type: text/x-patch
Size: 1914 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160726/afe9f128/attachment.bin>


More information about the cfe-commits mailing list