Re: [PATCH] Fix compiler warnings by using designated initializers

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Zakariyah Ali <zakariyahali100(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] Fix compiler warnings by using designated initializers
Date: 2026-06-10 13:34:45
Message-ID: 48173f3d-060a-4936-bfab-46ec30a813e5@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 04.06.26 18:36, Tom Lane wrote:
> Zakariyah Ali <zakariyahali100(at)gmail(dot)com> writes:
>> Use C99 designated initializers (.type = T_ErrorSaveContext) instead of the
>> standard initializer {T_ErrorSaveContext} when initializing ErrorSaveContext.
>> This avoids missing-field-initializers compiler warnings for the remaining fields of
>> the struct (e.g. error_occurred).
>
> What compiler produces such warnings? I'm not really eager to make
> invasive, more-typing-required changes like this, especially when
> it's not obvious that the modified code is any more correct.

I think -Wmissing-field-initializers was meant here.

It looks like all of the changes are of the form

- ErrorSaveContext escontext = {T_ErrorSaveContext};
+ ErrorSaveContext escontext = {.type = T_ErrorSaveContext};

Maybe we could do this more elegantly and safer with a non-pointer
variant of makeNode/newNode.

Like

#define initNode(_type_) ((_type_){.type = T_##_type_})

ErrorSaveContext escontext = initNode(ErrorSaveContext);

(Or something else instead of "init".)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2026-06-10 13:44:45 Re: Fix missing semicolon in pl_gram.y for option_value rule
Previous Message ZizhuanLiu X-MAN 2026-06-10 13:28:13 Re: Return value of XLogInsertRecord() for XLOG_SWITCH record