https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83048
--- Comment #2 from Tom de Vries ---
I wonder if we could use a macro like this:
...
#define SAFE_MACRO_STMT(stmt) \
do { \
if (1) \
stmt; \
else\
{}\
if (0) \
stmt; \
} while (0)
#if ERROR == 0
// No warning or error
#define foo return
#elif ERROR == 1
// error: else without a previous if
#define foo return;
#elif ERROR == 2
// error: else without a previous if
#define foo return; return
#elif ERROR == 3
// warning: suggest explicit braces to avoid ambiguous else [-Wparentheses]
#define foo if (1) return; else return
#else
#error "Invalid value of ERROR"
#endif
void
bar (void)
{
SAFE_MACRO_STMT (foo);
}
...
If we wrap all target macro calls in SAFE_MACRO_STMT we trigger an error or a
warning if the target macro implementation is not equivalent to a single stmt.