hokein created this revision. hokein added a reviewer: bkramer. hokein added a subscriber: cfe-commits.
The further solution is to add the missing header to the file where the symbol comes from. http://reviews.llvm.org/D20950 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 @@ -44,6 +44,8 @@ llvm::MemoryBuffer::getMemBuffer("\n")); InMemoryFileSystem->addFile("dir/otherdir/qux.h", 0, llvm::MemoryBuffer::getMemBuffer("\n")); + InMemoryFileSystem->addFile("header.h", 0, + llvm::MemoryBuffer::getMemBuffer("bar b;")); return Invocation.run(); } @@ -186,6 +188,11 @@ runIncludeFixer("int test = a::b::Green;\n")); } +TEST(IncludeFixer, IgnoreSymbolFromHeader) { + std::string Code = "#include \"header.h\""; + EXPECT_EQ(Code, runIncludeFixer(Code)); +} + // FIXME: add test cases for inserting and sorting multiple headers when // include-fixer supports multiple headers insertion. TEST(IncludeFixer, InsertAndSortSingleHeader) { Index: include-fixer/IncludeFixer.cpp =================================================================== --- include-fixer/IncludeFixer.cpp +++ include-fixer/IncludeFixer.cpp @@ -86,6 +86,15 @@ if (getCompilerInstance().getSema().isSFINAEContext()) return clang::TypoCorrection(); + // We currently ignore the unidentified symbol which is not from the + // main file. + // + // FIXME: Add the missing header to the header file where the symbol comes + // from. + if (!getCompilerInstance().getSourceManager().isWrittenInMainFile( + Typo.getLoc())) + return clang::TypoCorrection(); + std::string TypoScopeString; if (S) { // FIXME: Currently we only use namespace contexts. Use other context
Index: unittests/include-fixer/IncludeFixerTest.cpp =================================================================== --- unittests/include-fixer/IncludeFixerTest.cpp +++ unittests/include-fixer/IncludeFixerTest.cpp @@ -44,6 +44,8 @@ llvm::MemoryBuffer::getMemBuffer("\n")); InMemoryFileSystem->addFile("dir/otherdir/qux.h", 0, llvm::MemoryBuffer::getMemBuffer("\n")); + InMemoryFileSystem->addFile("header.h", 0, + llvm::MemoryBuffer::getMemBuffer("bar b;")); return Invocation.run(); } @@ -186,6 +188,11 @@ runIncludeFixer("int test = a::b::Green;\n")); } +TEST(IncludeFixer, IgnoreSymbolFromHeader) { + std::string Code = "#include \"header.h\""; + EXPECT_EQ(Code, runIncludeFixer(Code)); +} + // FIXME: add test cases for inserting and sorting multiple headers when // include-fixer supports multiple headers insertion. TEST(IncludeFixer, InsertAndSortSingleHeader) { Index: include-fixer/IncludeFixer.cpp =================================================================== --- include-fixer/IncludeFixer.cpp +++ include-fixer/IncludeFixer.cpp @@ -86,6 +86,15 @@ if (getCompilerInstance().getSema().isSFINAEContext()) return clang::TypoCorrection(); + // We currently ignore the unidentified symbol which is not from the + // main file. + // + // FIXME: Add the missing header to the header file where the symbol comes + // from. + if (!getCompilerInstance().getSourceManager().isWrittenInMainFile( + Typo.getLoc())) + return clang::TypoCorrection(); + std::string TypoScopeString; if (S) { // FIXME: Currently we only use namespace contexts. Use other context
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits