[clang-tools-extra] r276761 - [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:32:43 PDT 2016
Author: hokein
Date: Tue Jul 26 11:32:42 2016
New Revision: 276761
URL: http://llvm.org/viewvc/llvm-project?rev=276761&view=rev
Log:
[include-fixer] Don't add qualifiers in missing complete type cases.
Summary: In missing complete type cases, we don't know where to add the qualifiers.
Reviewers: bkramer
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D22812
Modified:
clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
Modified: clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp?rev=276761&r1=276760&r2=276761&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp Tue Jul 26 11:32:42 2016
@@ -73,6 +73,7 @@ public:
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 @@ llvm::Expected<tooling::Replacements> cr
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);
Modified: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp?rev=276761&r1=276760&r2=276761&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp Tue Jul 26 11:32:42 2016
@@ -335,6 +335,11 @@ namespace c {
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
More information about the cfe-commits
mailing list