Concerning RAII: How to prevent errors caused by accidentally creating a temporary?
<p>A while age a colleague told me he spent lot of time debugging a race condition. The culprit turned out to be something like this:</p>

<pre><code>void foo()
{
    ScopedLock(this-&gt;mutex); // Oops, should have been a named object.
                             // Edit: added the "this-&gt;" to fix compilation issue.
    // ....
}
</code></pre>

<p>In order to prevent situation from happening again he created the following macro after the definition of the ScopedLock class:</p>

<pre><code>#define ScopedLock(...) Error_You_should_create_a_named_object;
</code></pre>

<p>This patch works fine.</p>

<p>Does anyone know any other interesting techniques to prevent this problem?</p>
