qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [Qemu-devel] [PATCH 4/3] checkpatch: Enforce proper d


From: Eric Blake
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 4/3] checkpatch: Enforce proper do/while (0) style
Date: Fri, 1 Dec 2017 08:22:08 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

On 12/01/2017 01:31 AM, Markus Armbruster wrote:
Eric Blake <address@hidden> writes:

On 11/30/2017 08:01 AM, Eric Blake wrote:
while (0) is only idiomatic in a macro definition, where the caller
will be supplying the trailing ';'.  Warn if the macro has a duplicate.



+# 'while (0);' is odd; only macros should use while (0), without trailing ;
+               if ($line =~ /while\s*\(0\);/) {

Should this also check for uses of 'while (false);' ?

Do we think it's likely to occur?

Not as frequent, but it does appear in the code base.


Interestingly enough, we have an instance of 'do/while (false);' in
tests/vhost-user-bridge.c that is NOT in a macro, but is used for the
convenience of being able to 'break;' out early rather than using a
goto.  Similarly for chardev/char-serial.c using 'while (0);' outside
of a macro.

That "cure" merely adds gratuitous cleverness to the "disease".

              Those may be worth rewriting to use goto as separate
patches if we want to restrict ALL use of 'while \((0|false)\);'

I'd support that.


Okay, I'll post a v2 along those lines.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]