How to check/detect if clause without curly braces?
<p>I would like to find in a c/c++ code project all <em>if/else</em> sentences which are not using curly braces. Is there any compiler check or utility to find them?</p>

<p>The main problem is that I want to redefine some debug macros to avoid traces evaluation in some conditions (does any know any other solution?).  And I need to find them to avoid the <a href="http://en.wikipedia.org/wiki/Dangling_else" rel="nofollow">“dangling-else problem”</a>, as pointed out in <a href="http://stackoverflow.com/questions/11734604/if-block-without-curly-braces-makes-subsequent-else-if-nested">&quot;if&quot; block without curly braces makes subsequent &quot;else if&quot; nested</a></p>

<p>Code pieces:</p>

<p>Before modification:</p>

<pre><code>DEBUG GET_DEBUG_DST(DEBUG_LEVEL_DEBUG).nospace() &lt;&lt; DEBUG_PREFIX &lt;&lt; __PRETTY_FUNCTION__
</code></pre>

<p>Now we would use a if without braces inside:</p>

<pre><code>DEBUG if (getDebugmode(DEBUG_LEVEL_DEBUG)) GET_DEBUG_DST(DEBUG_LEVEL_DEBUG).nospace() &lt;&lt; DEBUG_PREFIX &lt;&lt; __PRETTY_FUNCTION__
</code></pre>

<p>Example of problematic code:</p>

<pre><code>if (my condition)
    DEBUG &lt;&lt; "hi there";
else
    {some more code;}
</code></pre>
