224 – Incorrect warning "no return at end of function"

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 224 - Incorrect warning "no return at end of function"
Summary: Incorrect warning "no return at end of function"
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P3 minor
Assignee: Walter Bright
URL:
Keywords: diagnostic, rejects-valid
Depends on:
Blocks:
Reported: 2006年06月25日 05:02 UTC by Matti Niemenmaa
Modified: 2014年02月15日 13:22 UTC (History)
0 users

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 Matti Niemenmaa 2006年06月25日 05:02:30 UTC
int main() {
	// or for (;;), or while (true), or do...while(true);
	if (true)
		return 0;
}
Such code generates (when compiled with -w) the warning "function module.main no return at end of function".
But, of course, if allowed to compile, the function would return 0.
Comment 1 Jarrett Billingsley 2006年06月25日 16:21:56 UTC
With the simplistic flow analysis in D (read: virtually none), it can't tell that the conditional is always taken. That if statement might not be optimized out until after the function "flow analysis" is done. Which is why this is a warning and not an error, or else it'd probably give the same warning for half the functions that you write. All it checks for is if the last statement of the function is a return, and in this case, it isn't.
Comment 2 Walter Bright 2008年07月09日 22:31:13 UTC
Fixed dmd 1.032 and 2.016


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