[include-fixer] Desugar incomplete types.
This will look through typedefs so include-fixer will look up the target
of the typedef instead of the typedef itself (which is already in
scope).
llvm-svn: 289952
GitOrigin-RevId: bc805aef33da0f642c2e8cb6b33491a4038155b5
diff --git a/include-fixer/IncludeFixer.cpp b/include-fixer/IncludeFixer.cpp
index 20683e0..ad3f8e9 100644
--- a/include-fixer/IncludeFixer.cpp
+++ b/include-fixer/IncludeFixer.cpp
@@ -153,8 +153,8 @@
return false;
clang::ASTContext &context = CI->getASTContext();
- std::string QueryString =
- T.getUnqualifiedType().getAsString(context.getPrintingPolicy());
+ std::string QueryString = QualType(T->getUnqualifiedDesugaredType(), 0)
+ .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.
std::vector<find_all_symbols::SymbolInfo> MatchedSymbols =
diff --git a/unittests/include-fixer/IncludeFixerTest.cpp b/unittests/include-fixer/IncludeFixerTest.cpp
index 756c258..c7737c8 100644
--- a/unittests/include-fixer/IncludeFixerTest.cpp
+++ b/unittests/include-fixer/IncludeFixerTest.cpp
@@ -136,6 +136,10 @@
"namespace std {\nclass string;\n}\nstd::string foo;\n",
runIncludeFixer("#include \"foo.h\"\n"
"namespace std {\nclass string;\n}\nstring foo;\n"));
+
+ EXPECT_EQ("#include <string>\n"
+ "class string;\ntypedef string foo;\nfoo f;\n",
+ runIncludeFixer("class string;\ntypedef string foo;\nfoo f;\n"));
}
TEST(IncludeFixer, MinimizeInclude) {