From patchwork Mon Sep 9 19:41:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 273664 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 34B522C010C for ; Tue, 10 Sep 2013 05:44:27 +1000 (EST) Received: from localhost ([::1]:53441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ7Np-0001tb-1I for incoming@patchwork.ozlabs.org; Mon, 09 Sep 2013 15:44:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ7Lu-00085F-Ej for qemu-devel@nongnu.org; Mon, 09 Sep 2013 15:42:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJ7Lp-0005Y2-T0 for qemu-devel@nongnu.org; Mon, 09 Sep 2013 15:42:26 -0400 Received: from mail-ob0-x236.google.com ([2607:f8b0:4003:c01::236]:46385) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ7Lp-0005Xu-MY for qemu-devel@nongnu.org; Mon, 09 Sep 2013 15:42:21 -0400 Received: by mail-ob0-f182.google.com with SMTP id wo10so6443560obc.27 for ; Mon, 09 Sep 2013 12:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZJJ5V3Y1wRqWNX22e6KuxO6cLGIfDV5BrZX/wsCNPk4=; b=0qtwD0H4rVwbVy89Ykg3KpnzNCv546cFNxGZZDf9YFtB/AqtNa6/yTkm9NeBcjN7QJ PKTQsNtd3Qo+9bHwN7QZTzg59zVIBrL1+Vlf+UeiktuLUhsqkqOby/httKdjtVigUUOP vU3Xj9G4ZRtIYxWShnQz+DcFFSr8BOobs9V4ylHbQsv4wQQftkGfgrk1fKvwmDpfB44j E6LLQRH0vj7tpZDNn9fy6CHHDjokCvVh0Ycph7vQmBbYasNeDSKmhzNO2H9wlRmuyf9Z TzfaHIaduwfGBoiok8ZMROaUApReG/jm8H0PI1wnFFvXbjyqRGJ7K7rJmf8FWp+r8bDY LNQA== X-Received: by 10.60.65.37 with SMTP id u5mr1171805oes.72.1378755741117; Mon, 09 Sep 2013 12:42:21 -0700 (PDT) Received: from loki.austin.ibm.com ([32.97.110.51]) by mx.google.com with ESMTPSA id hl3sm14443740obb.0.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 09 Sep 2013 12:42:17 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 9 Sep 2013 14:41:34 -0500 Message-Id: <1378755701-2051-4-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1378755701-2051-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1378755701-2051-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::236 Cc: peter.maydell@linaro.org, tomoki.sekiyama@hds.com Subject: [Qemu-devel] [PATCH 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 From: Tomoki Sekiyama 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 Signed-off-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 =~ /^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)(?:\$|)/) { @@ -1969,6 +1969,9 @@ sub process { asm|__asm__)$/x) { + # Ignore 'catch (...)' in C++ + } elsif ($name =~ /^catch$/ && $realfile =~ /(\.cpp|\.h)$/) { + # cpp #define statements have non-optional spaces, ie # if there is a space between the name and the open # parenthesis it is simply not a parameter group. @@ -1992,7 +1995,7 @@ sub process { \+=|-=|\*=|\/=|%=|\^=|\|=|&=| =>|->|<<|>>|<|>|=|!|~| &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%| - \?|: + \?|::|: }x; my @elements = split(/($ops|;)/, $opline); my $off = 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 =~ /Wx[WE]/ && + $line =~ /class/ && $realfile =~ /(\.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 =~ /::$/ && $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/) { @@ -2135,6 +2145,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+>/) ||