Bug 252 – -w and switch returns = bogus "no return at end of function" warning

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-07-14T17:04:00Z
Last change time
2014-02-15T13:18:33Z
Keywords
diagnostic, rejects-valid
Assigned to
bugzilla
Creator
jpelcis

Comments

Comment #0 by jpelcis — 2006-07-14T17:04:34Z
char[] foo (int bar) { switch (bar) { case 1: return "1"; case 2: return "2"; default: return "many"; } } Compiling this gives the following incorrect error message: C:\programs>dmd -w test.d warning - test.d(1): function test.foo no return at end of function Severity is minor because there are at least 3 easy workarounds: Use if-else. Assign to a temporary variable and return that outside of the switch. Place a return immediately after the switch.
Comment #1 by smjg — 2007-02-11T20:04:22Z
Probably part of the same bug: If you add a statement after the switch, it fails to report "statement is not reachable".
Comment #2 by bugzilla — 2008-07-01T23:21:53Z
*** Bug 1169 has been marked as a duplicate of this bug. ***
Comment #3 by davidl — 2008-07-02T04:07:27Z
seems this code compiles fine in dmd 1.031
Comment #4 by davidl — 2008-07-02T04:10:48Z
sorry ... it's a warning related issue...reopened
Comment #5 by bugzilla — 2008-07-09T22:31:36Z
Fixed dmd 1.032 and 2.016