Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fAma2-0003iF-MC for pgsql-committers@arkaria.postgresql.org; Tue, 24 Apr 2018 01:17:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fAma1-00035J-AQ for pgsql-committers@arkaria.postgresql.org; Tue, 24 Apr 2018 01:17:13 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fAma1-00035A-2A for pgsql-committers@lists.postgresql.org; Tue, 24 Apr 2018 01:17:13 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fAmZy-00061D-0n for pgsql-committers@lists.postgresql.org; Tue, 24 Apr 2018 01:17:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w3O1H5na009588; Mon, 23 Apr 2018 21:17:05 -0400 From: Tom Lane To: David Rowley cc: Alvaro Herrera , pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Remove useless default clause in switch In-reply-to: References: Comments: In-reply-to David Rowley message dated "Tue, 24 Apr 2018 12:27:27 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9586.1524532625.1@sss.pgh.pa.us> Date: Mon, 23 Apr 2018 21:17:05 -0400 Message-ID: <9587.1524532625@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David Rowley writes: > On 24 April 2018 at 03:12, Alvaro Herrera 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