I have a ScopedLock
class which can help to release lock automatically when running out of scope.
However, the problem is: Sometimes team members write invalid lock-code such as
{
ScopedLock(mutex); // anonymous
xxx;
}
The above code is wrong because the ScopedLock
object is constructed and destructed immediately, so it fails to lock the expected area (xxx
). I want the compiler to give an error when trying to compile such code. Can this be done?
I have searched g++
warning options, but fail to find the right one.
AFAIK there's no such a flag in gcc. A static analyzer may better suit your needs.