diff --git a/clang/test/Format/error-unfound-files.cpp b/clang/test/Format/error-unfound-files.cpp new file mode 100644 index 0000000000000..1cc57ed064fb4 --- /dev/null +++ b/clang/test/Format/error-unfound-files.cpp @@ -0,0 +1,5 @@ +// RUN: rm -f a.c b.c + +// RUN: not clang-format a.c b.c 2>&1 | FileCheck %s +// CHECK: a.c: +// CHECK-NEXT: b.c: diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 96fb85e99bf5f..91b9afd1e2861 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -410,7 +410,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) { const bool IsSTDIN = FileName == "-"; if (!OutputXML && Inplace && IsSTDIN) { errs() << "error: cannot use -i when reading from stdin.\n"; - return false; + return true; } // On Windows, overwriting a file with an open file mapping doesn't work, // so read the whole file into memory when formatting in-place. @@ -419,7 +419,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) { ? MemoryBuffer::getFileAsStream(FileName) : MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true); if (std::error_code EC = CodeOrErr.getError()) { - errs() << EC.message() << "\n"; + errs() << FileName << ": " << EC.message() << "\n"; return true; } std::unique_ptr Code = std::move(CodeOrErr.get());