From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCk48-00020J-NO for qemu-devel@nongnu.org; Mon, 10 Feb 2014 01:10:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WCk42-0004vZ-Na for qemu-devel@nongnu.org; Mon, 10 Feb 2014 01:10:00 -0500 Received: from smtp.mail.uni-mannheim.de ([134.155.96.80]:45960) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCk42-0004rU-Gb for qemu-devel@nongnu.org; Mon, 10 Feb 2014 01:09:54 -0500 Message-ID: <52F86D2D.2010406@weilnetz.de> Date: Mon, 10 Feb 2014 07:09:49 +0100 From: Stefan Weil MIME-Version: 1.0 References: <1391936581-8382-1-git-send-email-ehabkost@redhat.com> <20140210013306.GB16594@T430.nay.redhat.com> In-Reply-To: <20140210013306.GB16594@T430.nay.redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , Eduardo Habkost Cc: Peter Maydell , qemu-devel@nongnu.org, =?ISO-8859-1?Q?Andreas_F=E4rber?= , Paolo Bonzini Am 10.02.2014 02:33, schrieb Fam Zheng: > On Sun, 02/09 07:03, Eduardo Habkost wrote: >> We had an unwritten rule about declarations having to be at beginning of >> blocks. Make it a written rule. >> >> Signed-off-by: Eduardo Habkost >> --- >> CODING_STYLE | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/CODING_STYLE b/CODING_STYLE >> index dcbce28..f6eb319 100644 >> --- a/CODING_STYLE >> +++ b/CODING_STYLE >> @@ -84,3 +84,10 @@ and clarity it comes on a line by itself: >> Rationale: a consistent (except for functions...) bracing style reduces >> ambiguity and avoids needless churn when lines are added or removed. >> Furthermore, it is the QEMU coding style. >> + >> +5. Declarations >> + >> +Mixed declarations (interleaving statements and declarations within blocks) are >> +not allowed; declarations should be at beginning of blocks. In other words, at the beginning? >> +the code should not generate warnings if using GCC's >> +-Wdeclaration-after-statement option. > > What is the reason that we don't use -Wdeclaration-after-statement in Makefile? > Thanks. > > Fam Maybe that would be a good idea. I did a short test and added that flag in configure (where all gcc flags are checked before they are applied): diff --git a/configure b/configure index f7c672a..c10a1a8 100755 --- a/configure +++ b/configure @@ -331,6 +331,8 @@ ARFLAGS="${ARFLAGS-rv}" # default flags for all hosts QEMU_CFLAGS="-fno-strict-aliasing $QEMU_CFLAGS" QEMU_CFLAGS="-Wall -Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" +QEMU_CFLAGS="-Wdeclaration-after-statement $QEMU_CFLAGS" +QEMU_CFLAGS="-Wno-error=declaration-after-statement $QEMU_CFLAGS" QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" QEMU_INCLUDES="-I. -I\$(SRC_PATH) -I\$(SRC_PATH)/include" The first result already shows 194 different violations. See http://qemu.weilnetz.de/test/declaration-after-statement.txt for the build protocol. As this test does not cover all source paths, there might be even more violations. So the code will need some fixes before this rule can be checked by -Wdeclaration-after-statement. Until this is one, we could use -Wno-error=declaration-after-statement as I did in my test. The patch for CODING_STYLE is still useful. Reviewed-by: Stefan Weil Stefan