From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2Ulq-0000Sg-U5 for qemu-devel@nongnu.org; Thu, 25 Jul 2013 19:16:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2Ulp-0000ir-Q0 for qemu-devel@nongnu.org; Thu, 25 Jul 2013 19:16:30 -0400 Received: from mail-oa0-x235.google.com ([2607:f8b0:4003:c02::235]:53808) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2Ulp-0000ij-JX for qemu-devel@nongnu.org; Thu, 25 Jul 2013 19:16:29 -0400 Received: by mail-oa0-f53.google.com with SMTP id k14so5714769oag.26 for ; Thu, 25 Jul 2013 16:16:29 -0700 (PDT) Sender: fluxion Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <20130723224539.26273.63780.stgit@outback> References: <20130723224525.26273.28321.stgit@outback> <20130723224539.26273.63780.stgit@outback> Message-ID: <20130725231625.16294.42608@loki> Date: Thu, 25 Jul 2013 18:16:25 -0500 Subject: Re: [Qemu-devel] [PATCH v8 03/10] checkpatch.pl: Check .cpp files List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Tomoki Sekiyama , qemu-devel@nongnu.org Cc: libaiqing@huawei.com, ghammer@redhat.com, stefanha@gmail.com, lcapitulino@redhat.com, vrozenfe@redhat.com, pbonzini@redhat.com, seiji.aguchi@hds.com, lersek@redhat.com, areis@redhat.com Quoting Tomoki Sekiyama (2013-07-23 17:45:39) > Enable checkpatch.pl to apply the same checks as C source files for > C++ files with .cpp extensions. It also adds some exceptions for C++ > sources to suppress errors for: > - <> used in C++ template arguments (e.g. template ) > - :: used to represent namespaces (e.g. SomeClass::method()) > - : used in class declaration (e.g. class T : public Super) > - ~ used in destructor method name (e.g. T::~T()) > - spacing around 'catch' (e.g. catch (...)) > = > Signed-off-by: Tomoki Sekiyama = Reviewed-by: Michael Roth > --- > scripts/checkpatch.pl | 34 ++++++++++++++++++++++++++++------ > 1 file changed, 28 insertions(+), 6 deletions(-) > = > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index ec0aa4c..9d46e5a 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -1363,7 +1363,7 @@ sub process { > # Check for incorrect file permissions > if ($line =3D~ /^new (file )?mode.*[7531]\d{0,2}$/) { > my $permhere =3D $here . "FILE: $realfile\n"; > - if ($realfile =3D~ /(Makefile|Kconfig|\.c|\.h|\.S= |\.tmpl)$/) { > + if ($realfile =3D~ /(Makefile|Kconfig|\.c|\.cpp|\= .h|\.S|\.tmpl)$/) { > ERROR("do not set execute permissions for= source files\n" . $permhere); > } > } > @@ -1460,7 +1460,7 @@ sub process { > } > = > # check we are in a valid source file if not then ignore this hunk > - next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); > + next if ($realfile !~ /\.(h|c|cpp|s|S|pl|sh)$/); > = > #80 column limit > if ($line =3D~ /^\+/ && $prevrawline !~ /\/\*\*/ && > @@ -1495,7 +1495,7 @@ sub process { > } > = > # check we are in a valid source file C or perl if not then ignore this = hunk > - next if ($realfile !~ /\.(h|c|pl)$/); > + next if ($realfile !~ /\.(h|c|cpp|pl)$/); > = > # in QEMU, no tabs are allowed > if ($rawline =3D~ /^\+.* /) { > @@ -1505,7 +1505,7 @@ sub process { > } > = > # check we are in a valid C source file if not then ignore this hunk > - next if ($realfile !~ /\.(h|c)$/); > + next if ($realfile !~ /\.(h|c|cpp)$/); > = > # check for RCS/CVS revision markers > if ($rawline =3D~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { > @@ -1969,6 +1969,9 @@ sub process { > asm|__asm__)$/x) > { > = > + # Ignore 'catch (...)' in C++ > + } elsif ($name =3D~ /^catch$/ && $realfile =3D~ /= (\.cpp|\.h)$/) { > + > # cpp #define statements have non-optional spaces= , ie > # if there is a space between the name and the op= en > # parenthesis it is simply not a parameter group. > @@ -1992,7 +1995,7 @@ sub process { > \+=3D|-=3D|\*=3D|\/=3D|%=3D|\^=3D|\|=3D|&= =3D| > =3D>|->|<<|>>|<|>|=3D|!|~| > &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%| > - \?|: > + \?|::|: > }x; > my @elements =3D split(/($ops|;)/, $opline); > my $off =3D 0; > @@ -2062,6 +2065,10 @@ sub process { > # // is a comment > } elsif ($op eq '//') { > = > + # Ignore : used in class declaration in C= ++ > + } elsif ($opv eq ':B' && $ctx =3D~ /Wx[WE= ]/ && > + $line =3D~ /class/ && $r= ealfile =3D~ /(\.cpp|\.h)$/) { > + > # No spaces for: > # -> > # : when part of a bitfield > @@ -2088,7 +2095,10 @@ sub process { > } elsif ($op eq '!' || $op eq '~' || > $opv eq '*U' || $opv eq '-U' || > $opv eq '&U' || $opv eq '&&U') { > - if ($ctx !~ /[WEBC]x./ && $ca !~ = /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { > + if ($op eq '~' && $ca =3D~ /::$/ = && $realfile =3D~ /(\.cpp|\.h)$/) { > + # '~' used as a name of D= estructor > + > + } elsif ($ctx !~ /[WEBC]x./ && $c= a !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { > ERROR("space required bef= ore that '$op' $at\n" . $hereptr); > } > if ($op eq '*' && $cc =3D~/\s*$Mo= difier\b/) { > @@ -2135,6 +2145,18 @@ sub process { > } elsif ($ctx !~ /[EWC]x[CWE]/) { > my $ok =3D 0; > = > + if ($realfile =3D~ /\.cpp|\.h$/) { > + # Ignore template argumen= ts <...> in C++ > + if (($op eq '<' || $op eq= '>') && $line =3D~ /<.*>/) { > + $ok =3D 1; > + } > + > + # Ignore :: in C++ > + if ($op eq '::') { > + $ok =3D 1; > + } > + } > + > # Ignore email addresses > if (($op eq '<' && > $cc =3D~ /^\S+\@\S+>/) ||