Index: clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tidy/tool/ClangTidyMain.cpp +++ clang-tidy/tool/ClangTidyMain.cpp @@ -119,15 +119,23 @@ return 1; } + std::vector EnabledChecks = clang::tidy::getCheckNames(Options); + // FIXME: Allow using --list-checks without positional arguments. if (ListChecks) { llvm::outs() << "Enabled checks:"; - for (auto CheckName : clang::tidy::getCheckNames(Options)) + for (auto CheckName : EnabledChecks) llvm::outs() << "\n " << CheckName; llvm::outs() << "\n\n"; return 0; } + if (EnabledChecks.empty()) { + llvm::errs() << "Error: no checks enabled.\n"; + llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); + return 1; + } + std::vector Errors; clang::tidy::ClangTidyStats Stats = clang::tidy::runClangTidy(Options, OptionsParser.getCompilations(), Index: test/clang-tidy/diagnostic.cpp =================================================================== --- test/clang-tidy/diagnostic.cpp +++ test/clang-tidy/diagnostic.cpp @@ -1,7 +1,7 @@ // RUN: clang-tidy %s.nonexistent.cpp -- | FileCheck -check-prefix=CHECK1 %s // RUN: clang-tidy -checks='google-explicit-constructor' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK2 %s // RUN: clang-tidy -checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK3 %s -// RUN: clang-tidy -checks='-*,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s +// RUN: clang-tidy -checks='-*,misc-use-override,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s // CHECK1-NOT: warning // CHECK2-NOT: warning Index: test/clang-tidy/select-checks.cpp =================================================================== --- test/clang-tidy/select-checks.cpp +++ test/clang-tidy/select-checks.cpp @@ -1,6 +1,9 @@ // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp // RUN: clang-tidy %t.cpp -fix -checks='-*,llvm-*' -- // RUN: FileCheck -input-file=%t.cpp %s +// RUN: clang-tidy %s -checks='-*,an-unknown-check' -- 2>&1 | FileCheck -check-prefix=CHECK2 %s + +// CHECK2: Error: no checks enabled. namespace i { }