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 04:17:54
Message-ID: 6093.1545193074@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:
> It'd be nice if there were an easy way to write a switch() where the
> compiler enforces that all enum values are checked, but still had the
> possibility to have a 'default:' block for error checking... I can't
> quite come up with a good approach to emulate that though.

Yeah, that would sure make things better. I was considering
something like

switch (enumvalue)
{
case A: ...
case B: ...
...

#ifndef USE_ASSERT_CHECKING
default:
elog(ERROR, ...);
#endif
}

so that you get the runtime protection in production builds but not
debug builds ... except that yes, you really want that protection in
debug builds too. Maybe the #if could be on some other symbol so that
the default: is normally enabled in all builds, but we have some
lonely buildfarm animal that disables it and builds with -Werror to
get our attention for omitted cases?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2018-12-19 04:35:16 Re: Use an enum for RELKIND_*?
Previous Message Andres Freund 2018-12-19 04:17:20 What to name the current heap after pluggable storage / what to rename?