On Thu, Oct 29, 2015 at 6:13 PM, Eric Blake <ebl...@redhat.com> wrote:
>
> On 10/29/2015 03:48 AM, Leonid Bloch wrote:
> > Now, macro definition such as "#define abc(x) [x] = y" should pass
> > without an error.
>
> Do we even have macros like that? Without context, it seems like that
> macro definition is under-parenthesized, and that you wouldn't want to
> use abc(x) in an arbitrary expression for fear of precedence rules
> causing nasty surprises.

Yes, for example, in hw/net/e1000.c, there is:
#define getreg(x)    [x] = mac_readreg  (l: 1209)
#define putreg(x)    [x] = mac_writereg  (l: 1230)

This issue came up in the latest patches I've sent to e1000, and in
the RFC patches we have sent for e1000e.

Leonid.
>
> >
> > Signed-off-by: Leonid Bloch <leo...@daynix.com>
> > ---
> >  scripts/checkpatch.pl | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 455d94b..e7d9cce 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -1716,11 +1716,13 @@ sub process {
> >  #  2. at the beginning of a line for slice initialisers -- [0...10] = 5,
> >  #  3. inside a curly brace -- = { [0...10] = 5 }
> >  #  4. after a comma -- [1] = 5, [2] = 6
> > +#  5. in a macro definition -- #define abc(x) [x] = y
> >               while ($line =~ /(.*?\s)\[/g) {
> >                       my ($where, $prefix) = ($-[1], $1);
> >                       if ($prefix !~ /$Type\s+$/ &&
> >                           ($where != 0 || $prefix !~ /^.\s+$/) &&
> >                           $prefix !~ /{\s+$/ &&
> > +                         $prefix !~ /\#\s*define[^(]*\([^)]*\)\s+$/ &&
> >                           $prefix !~ /,\s+$/) {
> >                               ERROR("space prohibited before open square 
> > bracket '['\n" . $herecurr);
> >                       }
> >
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>

Reply via email to