This is an archive of the discontinued LLVM Phabricator instance.

clang-extra: fix incorrect use of std::lock_guard by adding variable name (identified by MSVC [[nodiscard]] error)
ClosedPublic

Authored by poelmanc on Jan 29 2021, 8:31 PM.

Details

Summary

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.

Diff Detail

Event Timeline

poelmanc created this revision.Jan 29 2021, 8:31 PM
poelmanc requested review of this revision.Jan 29 2021, 8:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 29 2021, 8:31 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
kadircet accepted this revision.Jan 31 2021, 11:20 PM

thanks, lgtm!

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

nit: we prefer Lock rather than Guard in other places. so s/Guard/Lock/

This revision is now accepted and ready to land.Jan 31 2021, 11:20 PM
poelmanc updated this revision to Diff 320594.Feb 1 2021, 2:02 PM

Change Guard to Lock.

poelmanc marked an inline comment as done.Feb 1 2021, 2:03 PM

s/Guard/Lock/! I don't have commit access so appreciate a push.