This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C/C++ PATCH to implement -Wmultistatement-macros (PR c/80116)
- From: Gerald Pfeifer <gerald at pfeifer dot com>
- To: David Malcolm <dmalcolm at redhat dot com>, Martin Sebor <msebor at gmail dot com>
- Cc: Marek Polacek <polacek at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>, Martin Sebor <msebor at redhat dot com>, Jason Merrill <jason at redhat dot com>
- Date: Sat, 10 Jun 2017 00:03:18 +0200 (CEST)
- Subject: Re: C/C++ PATCH to implement -Wmultistatement-macros (PR c/80116)
- Authentication-results: sourceware.org; auth=none
- References: <20170608164936.GV3413@redhat.com> <1496942649.7551.150.camel@redhat.com> <322f3053-7021-980f-c918-6c4666d82f32@gmail.com>
On Thu, 8 Jun 2017, David Malcolm wrote:
> How about:
>
> "Warn about unsafe multiple statement macros that appear to be guarded
> by a clause such as if, else, while, or for, in which only the first
> statement is actually guarded after the macro is expanded."
>
> or somesuch?
Yes, I like this.
On Thu, 8 Jun 2017, Martin Sebor wrote:
> I don't have strong feelings about the current wording but if it
> should be tweaked for accuracy I would suggest to use the formal
> term "controlling expression", similarly to -Wswitch-unreachable.
That sounds good to me.
Some comments on the original patch:
+Warn about macros expanding to multiple statements in a body of a conditional,
+such as @code{if}, @code{else}, @code{for}, or @code{while}.
"in the body of a $WHATEVER_WE_SHALL_CALL_IT"
+The can usually be fixed by wrapping the macro in a do-while loop:
Is there a particular reason for not using an if(1) { } statement?
Ah, of course, a following else statement would be impacted by that.
Do we want to note that in the documentation?
+This warning is enabled by @option{-Wall} in C and C++.
"for C and C++" instead of "in"?
I'm curious to see how many issues this is going to find in real-world
code out there!
Gerald