From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23968 invoked by alias); 15 Nov 2005 23:26:17 -0000 Received: (qmail 23911 invoked by uid 22791); 15 Nov 2005 23:26:13 -0000 Received: from exchange1.qualstar.com (HELO exchange1.qualstar.com) (216.101.63.18) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 15 Nov 2005 23:26:13 +0000 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: False positive warning: missing return statement and switch statements Date: Tue, 15 Nov 2005 23:26:00 -0000 Message-ID: <9E27B4AB55478346B9F7848926E49B7F011128A5@exchange1.qualstar.com> From: "Steven L. Zook" To: "Frans Englich" Cc: "MSX to GCC" Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2005-11/txt/msg00231.txt.bz2 int toInt(const Number num) { switch(num) { case Zero: return 0; case One: return 1; case Two: default: return 2; } }=20 This approach at least returns something without causing much code expansion. If you want to trust your code, this approach will silence the warnings without costing much at run-time. I guess that the compiler writers have a very difficult choice in these kind of warnings between under and over warning. Their choice may not work well for you.=20 -----Original Message----- From: Frans Englich [mailto:frans.englich@telia.com]=20 Sent: Tuesday, November 15, 2005 3:01 PM To: John Love-Jensen Cc: Steven L. Zook; MSX to GCC Subject: Re: False positive warning: missing return statement and switch statements On Tuesday 15 November 2005 22:47, John Love-Jensen wrote: > Hi Frans, > > > Obviously, I am looking at this the wrong way -- please explain. > > Improve your code safety using C++ capabilities: > > int toInt(const Number num) > { > switch(num) > { > case Zero: > return 0; > case One: > return 1; > case Two: > return 2; > default: > throw std::range_error("toInt(): enum Number out of range"); > } > } > > Then the warning goes away, and your code is better. Yupp, that's what I currently do, in my case it unfortunately becomes a significant amount of code for dummy tests(because I know I'm behaving). Cheers, Frans