[Bug other/83048] wrap multi-statement macros in do {} while (0)

2017-11-20 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83048

--- Comment #3 from Tom de Vries  ---
(In reply to Tom de Vries from comment #2)
> I wonder if we could use a macro like this:
> ...
> #define SAFE_MACRO_STMT(stmt) \

Submitted RFC at https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01782.html .

[Bug other/83048] wrap multi-statement macros in do {} while (0)

2017-11-20 Thread vries at gcc dot gnu.org
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.

[Bug other/83048] wrap multi-statement macros in do {} while (0)

2017-11-19 Thread vries at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83048

--- Comment #1 from Tom de Vries  ---
Already done:

7fbc9a6 [riscv] Wrap ASM_OUTPUT_LABELREF in do {} while (0)
df82c70 [mips] Wrap ASM_OUTPUT_LABELREF in do {} while (0)