Bug 2214 – No error if void function returns a non-void value

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-07-10T11:41:00Z
Last change time
2015-06-09T05:15:12Z
Keywords
accepts-invalid
Assigned to
bugzilla
Creator
2korden

Comments

Comment #0 by 2korden — 2008-07-10T11:41:58Z
void f() { return new Exception("stuff"); // no error is generated } void main() { return f(); } Result: Process returned 8990704 (0x892FF0) Is this by design or by accident?
Comment #1 by 2korden — 2008-07-10T14:17:44Z
I agree that this code is correct: void foo() { } void bar() { return foo(); } while I think that this isn't: void foo() { return -1; } Besides, if it *is* supposed to work this way, it should be mentioned in spec.
Comment #2 by matti.niemenmaa+dbugzilla — 2008-07-10T15:20:06Z
It is in the spec. http://www.digitalmars.com/d/1.0/statement.html#ReturnStatement "Expression is allowed even if the function specifies a void return type. The Expression will be evaluated, but nothing will be returned."