scoped_lock
constructor could be nodiscard
like in libstdc++
#89388
Labels
enhancement
Improving things as opposed to bug fixing, e.g. new or missing feature
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Consider this code:
The constructor of
std::scoped_lock
should have the[[nodiscard]]
attribute to catch mistakes like the one in the example, creating a temporaryscoped_lock
object and leaving the access of the global variable unguarded.If we use libstdc++, we get the following warning
ignoring temporary created by a constructor declared with 'nodiscard' attribute [-Wunused-value]
. Maybe we could also have thisnodiscard
attribute too.Note that for instance
lock_guard
works as expected, and has the ``nodiscard` attribute.The text was updated successfully, but these errors were encountered: