Index: clang-tools-extra/trunk/include-fixer/IncludeFixer.h =================================================================== --- clang-tools-extra/trunk/include-fixer/IncludeFixer.h +++ clang-tools-extra/trunk/include-fixer/IncludeFixer.h @@ -74,7 +74,7 @@ /// \param Style clang-format style being used. /// /// \return Replacements for inserting and sorting headers. -std::vector createInsertHeaderReplacements( +tooling::Replacements createInsertHeaderReplacements( StringRef Code, StringRef FilePath, StringRef Header, unsigned FirstIncludeOffset = -1U, const clang::format::FormatStyle &Style = clang::format::getLLVMStyle()); 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 @@ -382,12 +382,12 @@ return !Compiler.getDiagnostics().hasFatalErrorOccurred(); } -std::vector +tooling::Replacements createInsertHeaderReplacements(StringRef Code, StringRef FilePath, StringRef Header, unsigned FirstIncludeOffset, const clang::format::FormatStyle &Style) { if (Header.empty()) - return {}; + return tooling::Replacements(); // Create replacements for new headers. clang::tooling::Replacements Insertions; if (FirstIncludeOffset == -1U) { @@ -409,13 +409,7 @@ llvm::dbgs() << R.toString() << '\n'; }); - clang::tooling::Replacements Replaces = - formatReplacements(Code, Insertions, Style); - // FIXME: remove this when `clang::tooling::Replacements` is implemented as - // `std::vector`. - std::vector Results; - std::copy(Replaces.begin(), Replaces.end(), std::back_inserter(Results)); - return Results; + return formatReplacements(Code, Insertions, Style); } } // namespace include_fixer Index: clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp =================================================================== --- clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp +++ clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp @@ -169,7 +169,7 @@ } // FIXME: Insert the header in right FirstIncludeOffset. - std::vector Replacements = + tooling::Replacements Replacements = clang::include_fixer::createInsertHeaderReplacements( Code->getBuffer(), FilePath, InsertHeader, /*FirstIncludeOffset=*/0, InsertStyle); @@ -215,7 +215,7 @@ } // FIXME: Rank the results and pick the best one instead of the first one. - std::vector Replacements = + tooling::Replacements Replacements = clang::include_fixer::createInsertHeaderReplacements( /*Code=*/Buffer.get()->getBuffer(), FilePath, Context.Headers.front(), Context.FirstIncludeOffset, InsertStyle); @@ -231,9 +231,8 @@ Diagnostics.setClient(&DiagnosticPrinter, false); if (STDINMode) { - tooling::Replacements Replaces(Replacements.begin(), Replacements.end()); std::string ChangedCode = - tooling::applyAllReplacements(Code->getBuffer(), Replaces); + tooling::applyAllReplacements(Code->getBuffer(), Replacements); llvm::outs() << ChangedCode; return 0; } 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 @@ -74,12 +74,12 @@ IncludeFixerActionFactory Factory(*SymbolIndexMgr, FixerContext, "llvm"); runOnCode(&Factory, Code, "input.cc", ExtraArgs); - std::vector Replacements; - if (!FixerContext.Headers.empty()) { - Replacements = clang::include_fixer::createInsertHeaderReplacements( - Code, "input.cc", FixerContext.Headers.front(), - FixerContext.FirstIncludeOffset); - } + if (FixerContext.Headers.empty()) + return Code; + tooling::Replacements Replacements = + clang::include_fixer::createInsertHeaderReplacements( + Code, "input.cc", FixerContext.Headers.front(), + FixerContext.FirstIncludeOffset); clang::RewriterTestContext Context; clang::FileID ID = Context.createInMemoryFile("input.cc", Code); clang::tooling::applyAllReplacements(Replacements, Context.Rewrite);