Re: Use an enum for RELKIND_*?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Use an enum for RELKIND_*?
Дата
Msg-id 6093.1545193074@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Use an enum for RELKIND_*?  (Andres Freund <andres@anarazel.de>)
Ответы Re: Use an enum for RELKIND_*?  (Andres Freund <andres@anarazel.de>)
Список pgsql-hackers
Andres Freund <andres@anarazel.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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: What to name the current heap after pluggable storage / what torename?
Следующее
От: Andres Freund
Дата:
Сообщение: Re: Use an enum for RELKIND_*?