Discussion:
[png-mng-implement] Fwd: [glennrp/libpng] Apple clang 8.1.0 warnings (#156)
Glenn Randers-Pehrson
2017-03-29 16:02:22 UTC
Permalink
New libpng warnings. I don't know why clang is objecting to
what seems to be valid use of the comma. The warning messages
hint that using "(void)" would suppress the warnings.

I suspect that in most cases the warning could also be suppressed
by using semicolons instead of commas, and adding braces
if necessary, as in

if (test <= DBL_MAX)
{
++exp_b10; base=test;
}

in place of

if (test <= DBL_MAX)
++exp_b10, base = test;

Glenn

---------- Forwarded message ----------
From: Viktor Szakats <***@github.com>
Date: Wed, Mar 29, 2017 at 5:56 AM
Subject: [glennrp/libpng] Apple clang 8.1.0 warnings (#156)
To: glennrp/libpng <***@noreply.github.com>
Cc: Subscribed <***@noreply.github.com>


After this week's toolchain updates, the following, mostly -Wcomma warnings
appeared. Also included some existing const stripping warnings. This is so
when building libpng with -Weverything option, I haven't tested with other
warning levels. Anyhow some of these *may* be useful information.

png.c:2835:16: warning: possible misuse of comma operator here [-Wcomma]
recip = 1, power = -power;
^
png.c:2835:7: note: cast expression to void to silence warning
recip = 1, power = -power;
^~~~~~~~~
(void)( )
png.c:2913:25: warning: possible misuse of comma operator here [-Wcomma]
++exp_b10, base = test;
^
png.c:2913:16: note: cast expression to void to silence warning
++exp_b10, base = test;
^~~~~~~~~
(void)( )

[snip]
John Bowler
2017-03-30 02:01:27 UTC
Permalink
Yep, the original "Norcroft" ARM C compiler did this for a while, the
message was "warning no side effect in void context". That was the 90's

Plus ca change, plus ca meme chose.

John Bowler
Post by Glenn Randers-Pehrson
New libpng warnings. I don't know why clang is objecting to
what seems to be valid use of the comma. The warning messages
hint that using "(void)" would suppress the warnings.
I suspect that in most cases the warning could also be suppressed
by using semicolons instead of commas, and adding braces
if necessary, as in
if (test <= DBL_MAX)
{
++exp_b10; base=test;
}
in place of
if (test <= DBL_MAX)
++exp_b10, base = test;
Glenn
---------- Forwarded message ----------
Date: Wed, Mar 29, 2017 at 5:56 AM
Subject: [glennrp/libpng] Apple clang 8.1.0 warnings (#156)
After this week's toolchain updates, the following, mostly -Wcomma
warnings appeared. Also included some existing const stripping warnings.
This is so when building libpng with -Weverything option, I haven't
tested with other warning levels. Anyhow some of these *may* be useful
information.
png.c:2835:16: warning: possible misuse of comma operator here [-Wcomma]
recip = 1, power = -power;
^
png.c:2835:7: note: cast expression to void to silence warning
recip = 1, power = -power;
^~~~~~~~~
(void)( )
png.c:2913:25: warning: possible misuse of comma operator here [-Wcomma]
++exp_b10, base = test;
^
png.c:2913:16: note: cast expression to void to silence warning
++exp_b10, base = test;
^~~~~~~~~
(void)( )
[snip]
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
png-mng-implement mailing list
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
--
John Bowler <***@gmail.com>
+1 (541) 450-9885
PO BOX 3151
KERBY OR 97531-3151
USA
Glenn Randers-Pehrson
2017-03-30 11:03:07 UTC
Permalink
Thanks. The patches look OK to me. I'll pull them into
libpng-1.6.30beta01.

Glenn

---------- Forwarded message ----------
From: Viktor Szakats <***@github.com>
Date: Wed, Mar 29, 2017 at 8:15 PM
Subject: Re: [glennrp/libpng] Apple clang 8.1.0 warnings (#156)
To: glennrp/libpng <***@noreply.github.com>
Cc: Glenn Randers-Pehrson <***@gmail.com>, Comment <
***@noreply.github.com>


Issued two separate PRs to address the -Wcomma (#157
<https://github.com/glennrp/libpng/pull/157>) and -Wcast-qual (#158
<https://github.com/glennrp/libpng/pull/158>) warnings.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/glennrp/libpng/issues/156#issuecomment-290264475>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABe25vRGLh5N7rOvgbvgdRJKy4QlpJGVks5rqvQ9gaJpZM4MswbV>
.
John Bowler
2017-03-30 12:00:27 UTC
Permalink
Ok, perhaps I should be more clear; function-like macros with side effects
are an essential part of the language. The original UNIX 'putc'
implementation is a classic example. Attempting to outlaw the underlying
construct, in other words attempting to outlaw the comma operator, seems
like compiler over-reach.

I have a particular interest in this because I never use {} for a simple
conditional in libpng simply because the formatting rules make the
resultant code almost impossible for me to debug; a four line if/else
blossoms into and 8 line mess.

If you really seriously want to ban "," then let's get some reasonable
formatting rules for if {} else {}, do {} while () and so on.

Incidentally the Norcroft compiler warning was the correct one; it warns if
there is a voided expression with no side effect (or function call), so a
correct comma operation doesn't warn. clang could do this too, rather than
suggesting meaningless syntactic garbage, the fact that it doesn't shows
that the writers are reinventing the wheel, with added corners. Surely any
C programmer knows that the lhs of "," is voided?

John Bowler
​

Loading...