Skip to content

Commit 2ada09c

Browse files
committed
[clang-tidy] Improved --verify-config when using literal style in config file
Specifying checks using the literal style (|) in the clang-tidy config file is currently supported but was not implemented for the --verify-config options. This means that clang-tidy would work properly but, using the --verify-config option would raise an error due to some checks not being parsed properly. Fixes #53737
1 parent 23ffb2b commit 2ada09c

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " [-verify-config]\n";
454454

455455
static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob,
456456
StringRef Source) {
457-
llvm::StringRef Cur, Rest;
457+
llvm::StringRef Cur = CheckGlob;
458+
llvm::StringRef Rest = CheckGlob;
458459
bool AnyInvalid = false;
459-
for (std::tie(Cur, Rest) = CheckGlob.split(',');
460-
!(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
460+
while (!Cur.empty() || !Rest.empty()) {
461+
Cur = Rest.substr(0, Rest.find_first_of(",\n"));
462+
Rest = Rest.substr(Cur.size() + 1);
461463
Cur = Cur.trim();
464+
462465
if (Cur.empty())
463466
continue;
464467
Cur.consume_front("-");

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ Miscellaneous
251251
option is specified. Now ``clang-apply-replacements`` applies formatting only with
252252
the option.
253253

254+
- Fixed ``--verify-check`` option not properly parsing checks when using the
255+
literal operator in the ``.clang-tidy`` config
256+
254257
Improvements to include-fixer
255258
-----------------------------
256259

clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,15 @@
1818
// CHECK-VERIFY: command-line option '-checks': warning: check glob 'bad*glob' doesn't match any known check [-verify-config]
1919
// CHECK-VERIFY: command-line option '-checks': warning: unknown check 'llvm-includeorder'; did you mean 'llvm-include-order' [-verify-config]
2020
// CHECK-VERIFY: command-line option '-checks': warning: unknown check 'my-made-up-check' [-verify-config]
21+
22+
// RUN: echo -e 'Checks: |\n bugprone-argument-comment\n bugprone-assert-side-effect,\n bugprone-bool-pointer-implicit-conversion\n readability-use-anyof*' > %T/MyClangTidyConfig
23+
// RUN: clang-tidy -verify-config \
24+
// RUN: --config-file=%T/MyClangTidyConfig | FileCheck %s -check-prefix=CHECK-VERIFY-BLOCK-OK
25+
// CHECK-VERIFY-BLOCK-OK: No config errors detected.
26+
27+
// RUN: echo -e 'Checks: |\n bugprone-arguments-*\n bugprone-assert-side-effects\n bugprone-bool-pointer-implicit-conversion' > %T/MyClangTidyConfigBad
28+
// RUN: not clang-tidy -verify-config \
29+
// RUN: --config-file=%T/MyClangTidyConfigBad 2>&1 | FileCheck %s -check-prefix=CHECK-VERIFY-BLOCK-BAD
30+
// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 'bugprone-arguments-*' doesn't match any known check [-verify-config]
31+
// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown check 'bugprone-assert-side-effects'; did you mean 'bugprone-assert-side-effect' [-verify-config]
32+

0 commit comments

Comments
 (0)