From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrxHH-0007Jh-9o for qemu-devel@nongnu.org; Wed, 17 Mar 2010 13:43:31 -0400 Received: from [199.232.76.173] (port=50105 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrxHG-0007J7-RF for qemu-devel@nongnu.org; Wed, 17 Mar 2010 13:43:30 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NrxHG-00078E-Gf for qemu-devel@nongnu.org; Wed, 17 Mar 2010 13:43:30 -0400 Received: from mx20.gnu.org ([199.232.41.8]:6518) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NrxHF-00077w-Om for qemu-devel@nongnu.org; Wed, 17 Mar 2010 13:43:29 -0400 Received: from mail.codesourcery.com ([38.113.113.100]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NrxHE-0007Pc-5M for qemu-devel@nongnu.org; Wed, 17 Mar 2010 13:43:28 -0400 From: Paul Brook Subject: Re: [Qemu-devel] [PATCH] [TRIVIAL] usb-linux: remove unreachable default in switch statement Date: Wed, 17 Mar 2010 17:43:06 +0000 References: <1268053115.2130.4.camel@localhost.localdomain> <201003171708.04633.paul@codesourcery.com> <4BA10E49.90703@codemonkey.ws> In-Reply-To: <4BA10E49.90703@codemonkey.ws> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201003171743.06728.paul@codesourcery.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Paul Bolle , qemu-devel@nongnu.org > > If something should never happen (as in this case) then an abort/assert > > is completely appropriate. Once things get that screwed up there's no > > right answer, and the best thing we can do is terminate immediately to > > try and avoid further damage. > > This case was: > > switch (foo & 0x03) { > case 0: case 1: case 2: case 3: > default: > } > > The default is unreachable. Having it there just introduces more code > that serves no purpose. Unless someone does something totally foolish > and changes the mask in the switch statement, there's no way it will > ever be reachable. I mistakenly remembered this was using a symbolic mask rather than a literal 0x03. In that case I'd argue it's much easier to make the dumb error you describe, and the assert can be a handy cluebat. I guess it's largely personal preference - I prefer to add the default case to make it clear that falling through is never gong to be the right answer. Paul