[llvm-branch-commits] [clang-tools-extra] 76e4c93 - clang-extra: fix incorrect use of std::lock_guard by adding variable name (identified by MSVC [[nodiscard]] error)

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 22 12:08:13 PST 2021


Author: Conrad Poelman
Date: 2021-02-22T12:07:39-08:00
New Revision: 76e4c93ea42b3d23907611d14e347bfeae8d4b0a

URL: https://github.com/llvm/llvm-project/commit/76e4c93ea42b3d23907611d14e347bfeae8d4b0a
DIFF: https://github.com/llvm/llvm-project/commit/76e4c93ea42b3d23907611d14e347bfeae8d4b0a.diff

LOG: 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 0b70c86e2007d3f32968f0a7d9efe8eab3bf0f0a)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/support/Function.h b/clang-tools-extra/clangd/support/Function.h
index 2cac1b1e7f67..936800d56985 100644
--- a/clang-tools-extra/clangd/support/Function.h
+++ b/clang-tools-extra/clangd/support/Function.h
@@ -51,7 +51,7 @@ template <typename T> class Event {
     Subscription &operator=(Subscription &&Other) {
       // If *this is active, unsubscribe.
       if (Parent) {
-        std::lock_guard<std::recursive_mutex>(Parent->ListenersMu);
+        std::lock_guard<std::recursive_mutex> Lock(Parent->ListenersMu);
         llvm::erase_if(Parent->Listeners,
                        [&](const std::pair<Listener, unsigned> &P) {
                          return P.second == ListenerID;


        


More information about the llvm-branch-commits mailing list