Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-08 Thread Marek Polacek
On Thu, Jun 08, 2017 at 08:53:54AM -0600, Martin Sebor wrote: > > > I think I'll go with -Wmultistatement-expansion (without the dash). > > > > Fine with me, FWIW. > > I like this name better, but I think -Wmultistatement-macros > would be clearer (it also matches the CERT rule). Ok, I'll buy th

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-08 Thread Martin Sebor
I think I'll go with -Wmultistatement-expansion (without the dash). Fine with me, FWIW. I like this name better, but I think -Wmultistatement-macros would be clearer (it also matches the CERT rule). Martin

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-08 Thread Pedro Alves
On 06/08/2017 12:19 PM, Marek Polacek wrote: > On Thu, Jun 08, 2017 at 12:01:03PM +0100, Pedro Alves wrote: >> On 06/08/2017 11:29 AM, Marek Polacek wrote: >>> On Wed, Jun 07, 2017 at 08:02:42PM +0100, Pedro Alves wrote: Hi Marek, Nice warning! Just to confirm, would the patch warn

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-08 Thread Marek Polacek
On Thu, Jun 08, 2017 at 12:01:03PM +0100, Pedro Alves wrote: > On 06/08/2017 11:29 AM, Marek Polacek wrote: > > On Wed, Jun 07, 2017 at 08:02:42PM +0100, Pedro Alves wrote: > >> Hi Marek, > >> > >> Nice warning! Just to confirm, would the patch warn with code like: > > > > Thanks. BTW, if you (

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-08 Thread Pedro Alves
On 06/08/2017 11:29 AM, Marek Polacek wrote: > On Wed, Jun 07, 2017 at 08:02:42PM +0100, Pedro Alves wrote: >> Hi Marek, >> >> Nice warning! Just to confirm, would the patch warn with code like: > > Thanks. BTW, if you (or anyone) could come up with a better name, > I'm all ears. AFAICS, the w

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-08 Thread Marek Polacek
On Wed, Jun 07, 2017 at 08:02:42PM +0100, Pedro Alves wrote: > Hi Marek, > > Nice warning! Just to confirm, would the patch warn with code like: Thanks. BTW, if you (or anyone) could come up with a better name, I'm all ears. > const char * > target_xfer_status_to_string (enum target_xfer_st

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-07 Thread Pedro Alves
Hi Marek, Nice warning! Just to confirm, would the patch warn with code like: const char * target_xfer_status_to_string (enum target_xfer_status status) { #define CASE(X) case X: return #X switch (status) { CASE(TARGET_XFER_E_IO); CASE(TARGET_XFER_UNAVAILABLE); defa

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-07 Thread Marek Polacek
On Fri, Jun 02, 2017 at 03:50:12PM -0600, Martin Sebor wrote: > On 06/02/2017 10:52 AM, Marek Polacek wrote: > > On Thu, Jun 01, 2017 at 04:17:24PM -0600, Martin Sebor wrote: > > > Very nice. I think David already suggested handling other statements > > > besides if (do/while), so let me just add

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-02 Thread Martin Sebor
On 06/02/2017 10:52 AM, Marek Polacek wrote: On Thu, Jun 01, 2017 at 04:17:24PM -0600, Martin Sebor wrote: Very nice. I think David already suggested handling other statements besides if (do/while), so let me just add for and switch (as in: 'switch (1) case SWAP (i, j);') How's that one probl

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-02 Thread Marek Polacek
On Thu, Jun 01, 2017 at 04:17:24PM -0600, Martin Sebor wrote: > Very nice. I think David already suggested handling other statements > besides if (do/while), so let me just add for and switch (as in: > 'switch (1) case SWAP (i, j);') How's that one problematic, though? > The location in the warn

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-02 Thread Marek Polacek
On Thu, Jun 01, 2017 at 10:13:01PM +, Joseph Myers wrote: > On Thu, 1 Jun 2017, David Malcolm wrote: > > > The patch appears to only consider "if" and "else" clauses. Shouldn't > > it also cover "for", "while" and "do/while"? > > do/while would normally get a syntax error in the problem case

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-02 Thread Marek Polacek
On Thu, Jun 01, 2017 at 02:08:21PM -0400, David Malcolm wrote: > On Thu, 2017-06-01 at 18:45 +0200, Marek Polacek wrote: > > A motivating example for this warning can be found e.g. in > > > > PRE10-C. Wrap multistatement macros in a do-while loop > > https://www.securecoding.cert.org/confluenc

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-01 Thread Martin Sebor
On 06/01/2017 10:45 AM, Marek Polacek wrote: A motivating example for this warning can be found e.g. in PRE10-C. Wrap multistatement macros in a do-while loop https://www.securecoding.cert.org/confluence/x/jgL7 i.e., #define SWAP(x, y) \ tmp = x; \ x = y; \ y = tmp used like this [1

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-01 Thread Joseph Myers
On Thu, 1 Jun 2017, David Malcolm wrote: > The patch appears to only consider "if" and "else" clauses. Shouldn't > it also cover "for", "while" and "do/while"? do/while would normally get a syntax error in the problem cases. -- Joseph S. Myers jos...@codesourcery.com

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-01 Thread Trevor Saunders
On Thu, Jun 01, 2017 at 06:45:17PM +0200, Marek Polacek wrote: > A motivating example for this warning can be found e.g. in > > PRE10-C. Wrap multistatement macros in a do-while loop > https://www.securecoding.cert.org/confluence/x/jgL7 > > i.e., > > #define SWAP(x, y) \ > tmp = x; \ >

Re: C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-01 Thread David Malcolm
On Thu, 2017-06-01 at 18:45 +0200, Marek Polacek wrote: > A motivating example for this warning can be found e.g. in > > PRE10-C. Wrap multistatement macros in a do-while loop > https://www.securecoding.cert.org/confluence/x/jgL7 > > i.e., > > #define SWAP(x, y) \ > tmp = x; \ > x = y;

C/C++ PATCH to implement -Wmultiline-expansion (PR c/80116)

2017-06-01 Thread Marek Polacek
A motivating example for this warning can be found e.g. in PRE10-C. Wrap multistatement macros in a do-while loop https://www.securecoding.cert.org/confluence/x/jgL7 i.e., #define SWAP(x, y) \ tmp = x; \ x = y; \ y = tmp used like this [1] int x, y, z, tmp; if (z == 0) SWAP(x, y);