A lock object is created as a temporary, which unlocks again at the end of the statement
What it finds
std::lock_guard<std::mutex>(m);: the lock is a temporary without a name, destroyed at the end of the statement, so the code after it runs unlocked. The lock needs a name to hold until the end of its scope.
From the rule's source, unnamed_lock.rs.
Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/cpp:unnamed-lock" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/cpp:unnamed-lock] reason="..."tx0 explain tx0/cpp:unnamed-lock shows the same in the terminal. Found a false positive? Report it.