Bug 224 – Incorrect warning "no return at end of function"
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-06-25T05:02:00Z
Last change time
2014-02-15T13:22:09Z
Keywords
diagnostic, rejects-valid
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla
Comments
Comment #0 by matti.niemenmaa+dbugzilla — 2006-06-25T05:02:30Z
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 by jarrett.billingsley — 2006-06-25T16:21:56Z
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.