Index: clang/test/Format/line-ranges.cpp =================================================================== --- clang/test/Format/line-ranges.cpp +++ clang/test/Format/line-ranges.cpp @@ -9,3 +9,11 @@ // CHECK: {{^int\ \*i;$}} int * i; + +// RUN: not clang-format -lines=0:1 < %s 2>&1 \ +// RUN: | FileCheck -strict-whitespace -check-prefix=CHECK0 %s +// CHECK0: error: start line should be at least 1 + +// RUN: not clang-format -lines=2:1 < %s 2>&1 \ +// RUN: | FileCheck -strict-whitespace -check-prefix=CHECK1 %s +// CHECK1: error: start line should not exceed end line Index: clang/tools/clang-format/ClangFormat.cpp =================================================================== --- clang/tools/clang-format/ClangFormat.cpp +++ clang/tools/clang-format/ClangFormat.cpp @@ -246,8 +246,12 @@ errs() << "error: invalid : pair\n"; return true; } + if (FromLine < 1) { + errs() << "error: start line should be at least 1\n"; + return true; + } if (FromLine > ToLine) { - errs() << "error: start line should be less than end line\n"; + errs() << "error: start line should not exceed end line\n"; return true; } SourceLocation Start = Sources.translateLineCol(ID, FromLine, 1);