Re: pgsql: Remove useless default clause in switch - Mailing list pgsql-committers

From Tom Lane
Subject Re: pgsql: Remove useless default clause in switch
Date
Msg-id 9587.1524532625@sss.pgh.pa.us
Whole thread Raw
In response to Re: pgsql: Remove useless default clause in switch  (David Rowley <david.rowley@2ndquadrant.com>)
List 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 by date:

Previous
From: David Rowley
Date:
Subject: Re: pgsql: Remove useless default clause in switch
Next
From: Andrew Gierth
Date:
Subject: Re: pgsql: Remove useless default clause in switch