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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 252 - -w and switch returns = bogus "no return at end of function" warning
Summary: -w and switch returns = bogus "no return at end of function" warning
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 minor
Assignee: Walter Bright
URL:
Keywords: diagnostic, rejects-valid
: 1169 (view as issue list)
Depends on:
Blocks:
Reported: 2006年07月14日 17:04 UTC by James Pelcis
Modified: 2014年02月15日 13:18 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description James Pelcis 2006年07月14日 17:04:34 UTC
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 Stewart Gordon 2007年02月11日 20:04:22 UTC
Probably part of the same bug: If you add a statement after the switch, it fails to report "statement is not reachable".
Comment 2 Walter Bright 2008年07月01日 23:21:53 UTC
*** Bug 1169 has been marked as a duplicate of this bug. ***
Comment 3 david 2008年07月02日 04:07:27 UTC
seems this code compiles fine in dmd 1.031
Comment 4 david 2008年07月02日 04:10:48 UTC
sorry ... it's a warning related issue...reopened
Comment 5 Walter Bright 2008年07月09日 22:31:36 UTC
Fixed dmd 1.032 and 2.016


AltStyle によって変換されたページ (->オリジナル) /