From patchwork Thu Jun 6 15:06:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomoki Sekiyama X-Patchwork-Id: 249446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CBCA72C0090 for ; Fri, 7 Jun 2013 01:09:41 +1000 (EST) Received: from localhost ([::1]:36130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ukbop-0006l5-PK for incoming@patchwork.ozlabs.org; Thu, 06 Jun 2013 11:09:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkbnQ-0004z9-3L for qemu-devel@nongnu.org; Thu, 06 Jun 2013 11:08:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkbnK-0002JB-19 for qemu-devel@nongnu.org; Thu, 06 Jun 2013 11:08:12 -0400 Received: from usindpps06.hds.com ([207.126.252.19]:43456) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkbnJ-0002Iv-SO for qemu-devel@nongnu.org; Thu, 06 Jun 2013 11:08:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hds.com; h=subject : to : from : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=mail1; bh=XDLWNPNYQ+T0rKenD/8el8aHjLjHfo9xrtEt1MAyL/Q=; b=Ytra/Ft2m4Z4YjOcXgwlZiwJ1eYQGvnhLaoroWiXhsp564/RSaxpjApZVh+q5vOriS4L t632ujMkxrwof5PGhCGA2WZLc+CuB6taRm5DTCoET9PHw5QNkx3XVoABCAcL3QiVf0VU go4qljB7MyMy3UUmwVDQrR89qH550VuaV0xp1bxHYA6KTFeG4zBVkikSQiufVSI/HnEP Wtop2On+no4FmbovGaSyaCcuRijZS/QYwMwd/FtlV8qMKyYt/hmLHCo66N34TUWGbmdt u2Ek4/LgaWZYVtkLPZKHgxlUOsMivy7sKl9j+DpJbnIqmBqH3Wor1kMdgLAoLUyzv4y2 vw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hdsstg.com; h=subject : to : from : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=mail1; bh=XDLWNPNYQ+T0rKenD/8el8aHjLjHfo9xrtEt1MAyL/Q=; b=GCLX0mgZLpNdWREeksV+YJY6zs1CCbGZuLEXw0iPY1cn56WImY8FSr9W8NLxQG69xJoS nyLxorED1rSHdBC1uM7Y29RG6SmO7L1PgqKi/S1ZKPNUI0AIi2JLjthEmRCyrgWKFraY Oeb5wxVfQKIActN+9ptl6DdozKo/F+Yr/PpTqxOvd2tRvZlK6T469W6yKS24rzxEAzA1 YRLS5iWM/UegTUI5dQf1rSndt2CYcLaQn2flv8jwXxj2DwqHaUwnzSHMz1WHyjbtoVdm YyctQlhjaNLGMoGxiXZ2ZeGQku7q97/IvQGpDmIbQeJBMqGcxZkp2FJHU/kOxlkkKhki hw== Received: from usindmail01.hds.com (usindmail03 [207.126.252.22]) by usindpps06.hds.com (8.14.4/8.14.4) with ESMTP id r56F6amk025767; Thu, 6 Jun 2013 08:06:36 -0700 Received: from hds.com (usindnetf5d-vlan47float.corp.hds.com [10.74.73.11]) by usindmail01.hds.com (8.14.1/8.14.1) with ESMTP id r56F6YZj032872; Thu, 6 Jun 2013 11:06:34 -0400 (EDT) To: qemu-devel@nongnu.org From: Tomoki Sekiyama Date: Thu, 06 Jun 2013 11:06:34 -0400 Message-ID: <20130606150634.10486.29571.stgit@hds.com> In-Reply-To: <20130606150618.10486.60669.stgit@hds.com> References: <20130606150618.10486.60669.stgit@hds.com> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 mx ip4:207.126.244.0/26 ip4:207.126.252.0/25 include:mktomail.com include:cloud.hds.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8626, 1.0.431, 0.0.0000 definitions=2013-06-06_06:2013-06-06, 2013-06-06, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=outbound_policy score=0 spamscore=0 ipscore=0 suspectscore=1 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1211240000 definitions=main-1306060111 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 207.126.252.19 Cc: libaiqing@huawei.com, stefanha@gmail.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com, vrozenfe@redhat.com, pbonzini@redhat.com, seiji.aguchi@hds.com, areis@redhat.com Subject: [Qemu-devel] [PATCH v4 03/10] checkpatch.pl: check .cpp files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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()) Signed-off-by: Tomoki Sekiyama Reviewed-by: Laszlo Ersek --- scripts/checkpatch.pl | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ec0aa4c..53a12a8 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1363,7 +1363,7 @@ sub process { # Check for incorrect file permissions if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { my $permhere = $here . "FILE: $realfile\n"; - if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) { + if ($realfile =~ /(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 =~ /^\+/ && $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 =~ /^\+.*\t/) { @@ -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 =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { @@ -1992,7 +1992,7 @@ sub process { \+=|-=|\*=|\/=|%=|\^=|\|=|&=| =>|->|<<|>>|<|>|=|!|~| &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%| - \?|: + \?|::|: }x; my @elements = split(/($ops|;)/, $opline); my $off = 0; @@ -2066,7 +2066,8 @@ sub process { # -> # : when part of a bitfield } elsif ($op eq '->' || $opv eq ':B') { - if ($ctx =~ /Wx.|.xW/) { + if ($ctx =~ /Wx.|.xW/ && + !($opv eq ':B' && $line =~ /class/)) { ERROR("spaces prohibited around that '$op' $at\n" . $hereptr); } @@ -2088,7 +2089,11 @@ 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 =~ /::$/ && $realfile =~ /(\.cpp|\.h)$/) { + # '~' used as a name of Destructor + + } + elsif ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { ERROR("space required before that '$op' $at\n" . $hereptr); } if ($op eq '*' && $cc =~/\s*$Modifier\b/) { @@ -2126,8 +2131,9 @@ sub process { # A colon needs no spaces before when it is # terminating a case value or a label. + # Ignored if it is used in class declaration in C++. } elsif ($opv eq ':C' || $opv eq ':L') { - if ($ctx =~ /Wx./) { + if ($ctx =~ /Wx./ && $line !~ /class/) { ERROR("space prohibited before that '$op' $at\n" . $hereptr); } @@ -2135,6 +2141,18 @@ sub process { } elsif ($ctx !~ /[EWC]x[CWE]/) { my $ok = 0; + if ($realfile =~ /\.cpp|\.h$/) { + # Ignore template arguments <...> in C++ + if (($op eq '<' || $op eq '>') && $line =~ /<.*>/) { + $ok = 1; + } + + # Ignore :: in C++ + if ($op eq '::') { + $ok = 1; + } + } + # Ignore email addresses if (($op eq '<' && $cc =~ /^\S+\@\S+>/) ||