File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -217,7 +217,8 @@ void UseScopedLockCheck::diagOnSingleLock(
217217
218218 // Create Fix-its only if we can find the constructor call to properly handle
219219 // 'std::lock_guard l(m, std::adopt_lock)' case.
220- const auto *CtorCall = dyn_cast<CXXConstructExpr>(LockGuard->getInit ());
220+ const auto *CtorCall =
221+ dyn_cast_if_present<CXXConstructExpr>(LockGuard->getInit ());
221222 if (!CtorCall)
222223 return ;
223224
Original file line number Diff line number Diff line change @@ -364,6 +364,11 @@ Changes in existing checks
364364 on Windows when the check was enabled with a 32-bit :program: `clang-tidy `
365365 binary.
366366
367+ - Improved :doc: `modernize-use-scoped-lock
368+ <clang-tidy/checks/modernize/use-scoped-lock>` check by fixing a crash
369+ on malformed code (common when using :program: `clang-tidy ` through
370+ :program: `clangd `).
371+
367372- Improved :doc: `modernize-use-std-format
368373 <clang-tidy/checks/modernize/use-std-format>` check to correctly match
369374 when the format string is converted to a different type by an implicit
Original file line number Diff line number Diff line change 1+ // RUN: %check_clang_tidy -std=c++17-or-later -expect-clang-tidy-error %s modernize-use-scoped-lock %t -- -- -isystem %clang_tidy_headers
2+
3+ #include < mutex>
4+
5+ void f () {
6+ std::lock_guard<std::mutex> dont_crash {some_nonexistant_variable};
7+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'std::scoped_lock' instead of 'std::lock_guard' [modernize-use-scoped-lock]
8+ // CHECK-MESSAGES: :[[@LINE-2]]:43: error: use of undeclared identifier 'some_nonexistant_variable' [clang-diagnostic-error]
9+ }
You can’t perform that action at this time.
0 commit comments