Re: Use an enum for RELKIND_*?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Use an enum for RELKIND_*?
Date: 2018-12-19 14:55:22
Message-ID: 10268.1545231322@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andres Freund <andres(at)anarazel(dot)de> writes:
> On 2018-12-18 23:17:54 -0500, Tom Lane wrote:
>> Yeah, that would sure make things better. I was considering
>> something like
>>
>> #ifndef USE_ASSERT_CHECKING
>> default:
>> elog(ERROR, ...);
>> #endif

> Yea, that's the best I can come up with too. I think we'd probably want
> to have the warning available during development mainly, so I'm not sure
> the "lonely buildfarm animal" approach buys us enough.

Well, if it's controlled by some dedicated symbol ("CHECK_ENUM_SWITCHES"
or such) then you could certainly run a test compile with that turned
on, if you felt the need to. But I don't really buy the complaint
that leaving it to the buildfarm to find such problems wouldn't work.
They're almost always simple, easily-fixed oversights.

Also, if we wrap all this up in a macro then it'd be possible to do
other things by adjusting the macro. I'm envisioning

switch ((RelationRelkind) rel->rd_rel->relkind)
{
case ...
...

CHECK_ENUM_SWITCH(RelationRelkind, rel->rd_rel->relkind);
}

where the macro expands to empty when you want compiler warnings,
or to something like

default: elog(ERROR, "unsupported value %d of enum %s", ...)

in normal builds, or maybe some other way for special purposes.

(I guess pgindent would indent this as though it were part of the last
"case", which is slightly annoying, but if you leave a blank line
before it then that's probably fine.)

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Дмитрий Воронин 2018-12-19 15:54:28 Localization tools for Postgres
Previous Message David Rowley 2018-12-19 14:53:18 Re: Some memory allocations in gin fastupdate code are a bit brain dead