RFR of 8074819: Resolve disabled warnings for libzip

Martin Buchholz martinrb at google.com
Fri Jun 19 19:36:20 UTC 2015


There's a whole cottage industry of web sites explaining the do {...} while
(0) thing, e.g.
http://www.bruceblinn.com/linuxinfo/DoWhile.html

On Fri, Jun 19, 2015 at 11:47 AM, Ivan Gerasimov <ivan.gerasimov at oracle.com>
wrote:

>
>
> On 19.06.2015 15:11, Alan Bateman wrote:
>
>> On 18/06/2015 21:40, Xueming Shen wrote:
>>
>>> Hi,
>>>
>>> Please help review the change to resolve the disabled "parentheses"
>>> warnings for libzip
>>>
>>> issue: https://bugs.openjdk.java.net/browse/JDK-8074819
>>> webrev: http://cr.openjdk.java.net/~sherman/8074819
>>>
>> Looks okay to me, although I have to admit that parentheses warning is
>> new to me (I had to look it up).
>>
>>
> I think this warning would be avoided if ZIP_FORMAT_ERROR weren't defined
> as if..else
> #define ZIP_FORMAT_ERROR(message) \
>     if (1) { zip->msg = message; goto Catch; } else ((void)0)
>
> Because of this, the compiler sees "if () if () {} else {}" and issues
> warning, as it looks errorprone.
>
>
> I believe a more common idiom is using do..while(0) instead:
> #define ZIP_FORMAT_ERROR(message) \
>     do { zip->msg = message; goto Catch; }while (0)
>
> Sincerely yours,
> Ivan
>
>



More information about the core-libs-dev mailing list