Re: pgsql: Remove useless default clause in switch
| От | Tom Lane |
|---|---|
| Тема | Re: pgsql: Remove useless default clause in switch |
| Дата | |
| Msg-id | 9587.1524532625@sss.pgh.pa.us обсуждение |
| Ответ на | Re: pgsql: Remove useless default clause in switch (David Rowley <david.rowley@2ndquadrant.com>) |
| Список | pgsql-committers |
David Rowley <david.rowley@2ndquadrant.com> writes:
> On 24 April 2018 at 03:12, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
>> Remove useless default clause in switch
> I always thought that when all options were covered that we generally
> kept a default just in case someone added another enum and forgot to
> update the code.
Actually, there's an advantage to omitting the default for enum-based
switches, which is that many compilers will give you a compile-time
warning that you forgot a case. That beats an elog(ERROR) that you
might or might not hit in testing.
> There are other examples in that file with the switch
> (part_scheme->strategy), these are not using enums.
If it's not based on an enum then the compiler isn't going to understand
that you missed a value, so having the elog is better than having nothing.
regards, tom lane
В списке pgsql-committers по дате отправления: