[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 08:40:25 PDT 2016
hokein created this revision.
hokein added a reviewer: bkramer.
hokein added a subscriber: cfe-commits.
In missing complete type cases, we don't know where to add the qualifiers.
https://reviews.llvm.org/D22812
Files:
include-fixer/IncludeFixer.cpp
unittests/include-fixer/IncludeFixerTest.cpp
Index: unittests/include-fixer/IncludeFixerTest.cpp
===================================================================
--- unittests/include-fixer/IncludeFixerTest.cpp
+++ 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
Index: include-fixer/IncludeFixer.cpp
===================================================================
--- include-fixer/IncludeFixer.cpp
+++ 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22812.65531.patch
Type: text/x-patch
Size: 1770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160726/8f26d1f5/attachment.bin>
More information about the cfe-commits
mailing list