Bug 497545

Summary: bogus "value computed is not used" warning
Product: [Fedora] Fedora Reporter: Tom Lane <tgl>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: hhorak, jakub
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-04-27 20:12:20 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
bogus.c none

Description Tom Lane 2009-04-24 15:38:25 UTC
Created attachment 341194 [details]
bogus.c

Description of problem:
gcc 4.4 has begun to emit a warning about a perfectly sensible (and difficult to avoid) construct

Version-Release number of selected component (if applicable):
gcc-4.4.0-0.34.i586

How reproducible:
100%

Steps to Reproduce:
1. gcc -Wall -c bogus.c   (-O level seems not to matter)

Actual results:
bogus.c: In function 'main':
bogus.c:33: warning: value computed is not used
bogus.c:33: warning: value computed is not used

Expected results:
Silence

Additional info:
The example is a simplified extract from the postgresql sources.

This warning would only be reasonable if there were a better *and portable* way to do the same thing;
I do not wish to hear about workarounds involving gcc-isms.

Comment 1 Jakub Jelinek 2009-04-24 20:22:22 UTC
The right thing is obviously to cast the whole ?: to void instead of just one branch of the ?:, i.e. instead of
(((isnull) != NULL) ? *(isnull) = false : (void) NULL), (Datum) tup[1]
do
((void)(((isnull) != NULL) ? *(isnull) = false : false)), (Datum) tup[1]
and similarly for true and 0 instead of false and tup[1].

The warning appeared with the tuples merge, but isn't reproduceable with current 4.5, I'll look at what actually changed in this regard in the mean time.

Comment 2 Tom Lane 2009-04-24 22:00:27 UTC
Hmm, if that's the "right thing" then the logical conclusion is that the LHS of every comma expression in the universe must be explicitly cast to void, else the compiler might harass you.  Somehow I do not buy that.

Comment 3 Jakub Jelinek 2009-04-27 06:10:14 UTC
It is a gcc bug and I've fixed it already upstream, see
http://gcc.gnu.org/PR39889
This will be fixed in dist-f11 whenever I build new gcc (should be this week).

The reason why I said the earlier is that it makes much more sense to cast to void the whole ?: than just one of the branches.  And you wanted a portable
way, not a gcc-ism.  So I just explained a better and portable way as you requested.

Normally, in comma expressions for -Wunused-values you need to cast to void
whenever the LHS of it doesn't have side effects.  Of course in this case there is a side-effect, so it is a compiler bug.

Comment 4 Jakub Jelinek 2009-04-27 20:12:20 UTC
Should be fixed in gcc-4.4.0-3 in rawhide.