Skip to content

Commit 801f3a5

Browse files
authored
[clang-format] Print the names of unfound files in error messages (#113640)
Also fix the return status when `-i` is used with reading from stdin. Fixes #113631.
1 parent a8ef0b3 commit 801f3a5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: rm -f a.c b.c
2+
3+
// RUN: not clang-format a.c b.c 2>&1 | FileCheck %s
4+
// CHECK: a.c:
5+
// CHECK-NEXT: b.c:

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
410410
const bool IsSTDIN = FileName == "-";
411411
if (!OutputXML && Inplace && IsSTDIN) {
412412
errs() << "error: cannot use -i when reading from stdin.\n";
413-
return false;
413+
return true;
414414
}
415415
// On Windows, overwriting a file with an open file mapping doesn't work,
416416
// so read the whole file into memory when formatting in-place.
@@ -419,7 +419,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
419419
? MemoryBuffer::getFileAsStream(FileName)
420420
: MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true);
421421
if (std::error_code EC = CodeOrErr.getError()) {
422-
errs() << EC.message() << "\n";
422+
errs() << FileName << ": " << EC.message() << "\n";
423423
return true;
424424
}
425425
std::unique_ptr<llvm::MemoryBuffer> Code = std::move(CodeOrErr.get());

0 commit comments

Comments
 (0)