c++ - How to check/detect an 'if' clause without curly braces? -
in c/c++ code project, find if/else sentences not using curly braces. there compiler check or utility find them?
the main problem want redefine debug macros avoid traces evaluation in conditions (does know other solution?). , need find them avoid “dangling-else problem”, pointed out in "if" block without curly braces makes subsequent "else if" nested
code pieces:
before modification:
debug get_debug_dst(debug_level_debug).nospace() << debug_prefix << __pretty_function__
now use if
without braces inside:
debug if (getdebugmode(debug_level_debug)) get_debug_dst(debug_level_debug).nospace() << debug_prefix << __pretty_function__
example of problematic code:
if (my condition) debug << "hi there"; else {some more code;}
just invert logic, , put active part in else branch:
#define debug if( !getdebugmode( debug_level_debug ) ) \ ; \ else \ get_debug_dst( debug_level_debug ).nospace() \ << debug_prefix << __pretty_function__
since there matching else
if
, can't pick additional else
.
Comments
Post a Comment