Re: gcc 4.6 -Wunused-but-set-variable

Lists: pgsql-hackers
From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: gcc 4.6 -Wunused-but-set-variable
Date: 2011-06-15 20:23:27
Message-ID: 1308169407.30599.17.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Another set of new gcc 4.6 warnings:

readfuncs.c: In function ‘_readCaseWhen’:
readfuncs.c:875:567: warning: variable ‘token’ set but not used [-Wunused-but-set-variable]
readfuncs.c: In function ‘_readFromExpr’:
readfuncs.c:1159:568: warning: variable ‘token’ set but not used [-Wunused-but-set-variable]

read.c: In function ‘nodeTokenType’:
read.c:222:8: warning: variable ‘val’ set but not used [-Wunused-but-set-variable]

I couldn't see a way good way of programming around this (perhaps in the
second case, but it would get uselessly ugly), so perhaps just marking
the variables as potentially unused would be appropriate? See patch.

Attachment Content-Type Size
gcc-4.6-attribute-unused.patch text/x-patch 831 bytes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gcc 4.6 -Wunused-but-set-variable
Date: 2011-06-15 23:28:53
Message-ID: 9895.1308180533@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> I couldn't see a way good way of programming around this (perhaps in the
> second case, but it would get uselessly ugly), so perhaps just marking
> the variables as potentially unused would be appropriate? See patch.

Of course this would break not only on non-gcc compilers, but old
versions of gcc. I'd suggest a macro (cf PERL_UNUSED_DECL) and some
version checks at the site of the macro declaration (perhaps the ones
emitted by bison for its use of this construct will do).

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gcc 4.6 -Wunused-but-set-variable
Date: 2011-06-16 20:50:38
Message-ID: 1308257438.6721.14.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On ons, 2011-06-15 at 19:28 -0400, Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > I couldn't see a way good way of programming around this (perhaps in the
> > second case, but it would get uselessly ugly), so perhaps just marking
> > the variables as potentially unused would be appropriate? See patch.
>
> Of course this would break not only on non-gcc compilers, but old
> versions of gcc. I'd suggest a macro (cf PERL_UNUSED_DECL) and some
> version checks at the site of the macro declaration (perhaps the ones
> emitted by bison for its use of this construct will do).

Non-GCC compilers would be fine, because we define away __attribute__
there anyway, but on GCC itself, you're right, the "unused" attribute is
a bit more recent than ancient.

Actually, casting to void, which is the convention we already use
elsewhere, works for this, so done that way.