Index: include-fixer/tool/ClangIncludeFixer.cpp =================================================================== --- include-fixer/tool/ClangIncludeFixer.cpp +++ include-fixer/tool/ClangIncludeFixer.cpp @@ -211,9 +211,13 @@ tooling::Replacements Replacements = clang::include_fixer::createInsertHeaderReplacements( Code->getBuffer(), FilePath, Context.Headers[0], InsertStyle); - std::string ChangedCode = + auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replacements); - llvm::outs() << ChangedCode; + if (!ChangedCode) { + llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n"; + return 1; + } + llvm::outs() << *ChangedCode; return 0; } @@ -265,9 +269,13 @@ Diagnostics.setClient(&DiagnosticPrinter, false); if (STDINMode) { - std::string ChangedCode = + auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replacements); - llvm::outs() << ChangedCode; + if (!ChangedCode) { + llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n"; + return 1; + } + llvm::outs() << *ChangedCode; return 0; } Index: unittests/clang-tidy/ClangTidyTest.h =================================================================== --- unittests/clang-tidy/ClangTidyTest.h +++ unittests/clang-tidy/ClangTidyTest.h @@ -17,6 +17,7 @@ #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Tooling.h" +#include "llvm/ADT/Optional.h" #include #include @@ -121,7 +122,12 @@ Fixes.insert(Error.Fix.begin(), Error.Fix.end()); if (Errors) *Errors = Context.getErrors(); - return tooling::applyAllReplacements(Code, Fixes); + auto Result = tooling::applyAllReplacements(Code, Fixes); + if (!Result) { + // FIXME: propogate the error. + return ""; + } + return *Result; } #define EXPECT_NO_CHANGES(Check, Code) \