This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C/C++ PATCH to implement -Wmultistatement-macros (PR c/80116)

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!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]