News for hackers. Stuff that matters.
Re:C++20 Reference Card by thestoicattack on Wednesday January 29, 2020 @12:43PM (#22183460)
To avoid this insidious bug:

    std::lock_guard<std::mutex>(m);  // guard is immediately thrown away
versus the correct

    std::lock_guard<std::mutex> g(m);  // hold mutex til end of scope
Re:C++20 Reference Card by dgellow on Wednesday January 29, 2020 @12:58PM (#22183660)
Note for people who don’t see the difference: if a guard doesn’t have a name, it won’t survive until the end of the scope, thus doesn’t guard anything.
Re:C++20 Reference Card by ynfnehf on Wednesday January 29, 2020 @02:13PM (#22184626)
I might be wrong here, but I think that the first one is a declaration of a guard with the name m using the default constructor.

The same way that int (a); and int a; are equivalent.

So the guard should remain until end of scope, but won't guard anything.

Re:C++20 Reference Card by bstamour on Wednesday January 29, 2020 @02:31PM (#22184819)
Lock guard has no default constructor, so the line will in fact materialize a temporary lock guard around the mutex m, then throw it away at the semi-colon, thus locking nothing.
Re:C++20 Reference Card by clappski on Wednesday January 29, 2020 @02:29PM (#22184802)
lock_guard doesn’t have a default ctor, you have to pass a mutex (or presumably invoke a move ctor, but I can’t see one on cppref).