Skip to content

Commit 76e4c93

Browse files
poelmanctstellar
authored andcommitted
clang-extra: fix incorrect use of std::lock_guard by adding variable name (identified by MSVC [[nodiscard]] error)
`std::lock_guard` is an RAII class that needs a variable name whose scope determines the guard's lifetime. This particular usage lacked a variable name, meaning the guard could be destroyed before the line that it was indented to protect. This line was identified by building clang with the latest MSVC preview release, which declares the std::lock_guard constructor to be `[[nodiscard]]` to draw attention to such issues. Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D95725 (cherry picked from commit 0b70c86)
1 parent 3444f05 commit 76e4c93

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

clang-tools-extra/clangd/support/Function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ template <typename T> class Event {
5151
Subscription &operator=(Subscription &&Other) {
5252
// If *this is active, unsubscribe.
5353
if (Parent) {
54-
std::lock_guard<std::recursive_mutex>(Parent->ListenersMu);
54+
std::lock_guard<std::recursive_mutex> Lock(Parent->ListenersMu);
5555
llvm::erase_if(Parent->Listeners,
5656
[&](const std::pair<Listener, unsigned> &P) {
5757
return P.second == ListenerID;

0 commit comments

Comments
 (0)