Bug 180 – DMD accepts a function with a non-void return type but no return statements

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-06-07T07:19:00Z
Last change time
2014-02-15T13:19:20Z
Keywords
accepts-invalid
Assigned to
bugzilla
Creator
smjg

Comments

Comment #0 by smjg — 2006-06-07T07:19:46Z
The spec for ReturnStatement states: "At least one return statement is required if the function specifies a return type that is not void." However, the compiler fails to honour this requirement, as shown by the most trivial testcase: ---------- int main() {} ---------- Walter has mentioned that there's a reason to allow paths through a function that would walk off the end without returning. However, there is no reason that a function with a non-void return type should be allowed to have no return statements at all. The only possible exception is if the function explicitly throws an exception or assert(false), but if either of these is to be allowed instead of a single return statement then the spec would have to be modified to this effect. As such, the compiler should be reporting an error on such code as the above.
Comment #1 by bugzilla — 2006-06-30T20:27:47Z
Fixed DMD 0.162
Comment #2 by smjg — 2007-03-21T11:59:45Z
*** Bug 32 has been marked as a duplicate of this bug. ***