[hjl@gnu-tools-1 tmp]$ cat x.c #define TST_IF_RETURN(_s_func_) \ if (_s_func_) \ { \ } \ else #define TST_FUNC_ISW(_FUNC_, _func_) \ int \ tst_isw##_func_ (int debug_flg) \ { \ TST_IF_RETURN (_FUNC_) \ { \ } \ } extern int LOWER; TST_FUNC_ISW (LOWER, lower); [hjl@gnu-tools-1 tmp]$ /export/build/gnu/gcc-cet/release/usr/gcc-8.0.0-cet/bin/gcc -Wmultistatement-macros -S x.c x.c: In function ‘tst_iswlower’: x.c:12:3: warning: macro expands to multiple statements [-Wmultistatement-macros] { \ ^ x.c:18:1: note: in expansion of macro ‘TST_FUNC_ISW’ TST_FUNC_ISW (LOWER, lower); ^~~~~~~~~~~~ x.c:5:2: note: some parts of macro expansion are not guarded by this ‘else’ clause else ^ x.c:11:3: note: in expansion of macro ‘TST_IF_RETURN’ TST_IF_RETURN (_FUNC_) \ ^~~~~~~~~~~~~ x.c:18:1: note: in expansion of macro ‘TST_FUNC_ISW’ TST_FUNC_ISW (LOWER, lower); ^~~~~~~~~~~~ [hjl@gnu-tools-1 tmp]$
Another one: [hjl@gnu-tools-1 tmp]$ cat y.c #define TST_DO_REC(rec) \ for (rec=0; rec < 10; ++rec) #define TST_FUNC_ISW \ int \ tst_isw##_func_ (int debug_flg) \ { \ TST_DO_REC (debug_flg) \ { \ } \ } TST_FUNC_ISW [hjl@gnu-tools-1 tmp]$ /export/build/gnu/gcc-cet/release/usr/gcc-8.0.0-cet/bin/gcc -Wmultistatement-macros -S y.c y.c: In function ‘tst_isw_func_’: y.c:9:3: warning: macro expands to multiple statements [-Wmultistatement-macros] { \ ^ y.c:13:1: note: in expansion of macro ‘TST_FUNC_ISW’ TST_FUNC_ISW ^~~~~~~~~~~~ y.c:2:3: note: some parts of macro expansion are not guarded by this ‘for’ clause for (rec=0; rec < 10; ++rec) ^ y.c:8:3: note: in expansion of macro ‘TST_DO_REC’ TST_DO_REC (debug_flg) \ ^~~~~~~~~~ y.c:13:1: note: in expansion of macro ‘TST_FUNC_ISW’ TST_FUNC_ISW ^~~~~~~~~~~~ [hjl@gnu-tools-1 tmp]$
C++ doesn't warn. The problem is that we shouldn't warn (in the C FE) when a guard is followed by '{'.
Author: mpolacek Date: Tue Jul 25 09:49:08 2017 New Revision: 250498 URL: https://gcc.gnu.org/viewcvs?rev=250498&root=gcc&view=rev Log: PR c/81364 * c-parser.c (c_parser_else_body): Don't warn about multistatement macro expansion if the body is in { }. (c_parser_while_statement): Likewise. (c_parser_for_statement): Likewise. * Wmultistatement-macros-12.c: New test. Added: trunk/gcc/testsuite/c-c++-common/Wmultistatement-macros-12.c Modified: trunk/gcc/c/ChangeLog trunk/gcc/c/c-parser.c trunk/gcc/testsuite/ChangeLog
Fixed.