Re: [PATCH] Compile without warning with gcc's -Wtype-limits, -Wempty-body

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Compile without warning with gcc's -Wtype-limits, -Wempty-body
Date: 2013-01-15 03:26:39
Message-ID: 13473.1358220399@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> On 2013-01-14 20:39:05 -0500, Peter Eisentraut wrote:
>> On Tue, 2013-01-15 at 00:29 +0100, Andres Freund wrote:
>>> Independently from this patch, should we add -Wtype-limits to the
>>> default parameters?

>> I think we have had a discussion along this line before. I am against
>> fixing warnings from this option, because those changes would hide
>> errors if a variable's type changed from signed to unsigned or vice
>> versa, which could happen because of refactoring or it might be
>> dependent on system headers.

> Well, I already found a bug (although with very limited consequences) in
> the walsender code and one with graver consequences in code I just
> submitted. So I don't really see that being on-par with some potential
> future refactoring...

FWIW, I agree with Peter --- in particular, warning against "x >= MIN"
just because MIN happens to be zero and x happens to be unsigned is the
sort of nonsense up with which we should not put. Kowtowing to that
kind of warning makes the code less robust, not more so.

It's a shame that the compiler writers have not figured this out and
separated misguided pedantry from actually-useful warnings. If I assign
-1 to an unsigned variable, by all means tell me about *that*. Don't
tell me your opinion of whether an assertion check is necessary.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2013-01-15 03:33:45 Re: Patches for TODO item: Avoid truncating empty OCDR temp tables on COMMIT
Previous Message Gurjeet Singh 2013-01-15 03:25:39 Re: count(*) of zero rows returns 1