Re: warning: dereferencing type-punned pointer

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: Tatsuo Ishii <ishii(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: warning: dereferencing type-punned pointer
Date: 2024-07-24 18:09:49
Message-ID: 1254018.1721844589@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Eisentraut <peter(at)eisentraut(dot)org> writes:
> On 24.07.24 16:05, Tom Lane wrote:
>> I'm not very thrilled with these changes. It's not apparent why
>> your compiler is warning about these usages of IsA and not any other
>> ones,

> I think one difference is that normally IsA is called on a Node * (since
> you call IsA to decide what to cast it to), but in this case it's called
> on a pointer that is already of type ErrorSaveContext *.

Hmm. But there are boatloads of places where we call IsA on a
pointer of type Expr *, or sometimes other things. Why aren't
those triggering the same warning?

> I think here you could just bypass the SOFT_ERROR_OCCURRED macro:
> - if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
> + if (jsestate->escontext.error_occurred)

Perhaps. That's a bit sad because it's piercing a layer of
abstraction. I do not like compiler warnings that can't be
gotten rid of without making the code objectively worse.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2024-07-24 18:10:45 Re: [18] Policy on IMMUTABLE functions and Unicode updates
Previous Message Pavel Stehule 2024-07-24 18:01:01 Re: proposal: schema variables