Bug 438 – Compiler allows returning value from void function

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-10-17T04:33:00Z
Last change time
2014-02-15T13:18:53Z
Assigned to
bugzilla
Creator
vlasov

Comments

Comment #0 by vlasov — 2006-10-17T04:33:45Z
The following code compiles without errors void foo() { return false; } void bar() { return "bar"; } void main() { foo(); bar(); }
Comment #1 by casantander1 — 2006-10-17T08:31:00Z
Not a bug, see http://www.digitalmars.com/d/changelog1.html#new0116 "Can now return an expression from a function returning void"
Comment #2 by braddr — 2006-10-18T00:32:49Z
> http://d.puremagic.com/issues/show_bug.cgi?id=438 Can you point to where this is documented in the language spec and maybe some past threads discussing it? I'm really curious as to the reasons behind the choice. Thanks, Brad
Comment #3 by sean — 2006-10-18T08:15:17Z
Brad Roberts wrote: > > http://d.puremagic.com/issues/show_bug.cgi?id=438 > > Can you point to where this is documented in the language spec and maybe > some past threads discussing it? I'm really curious as to the reasons > behind the choice. I can understand accepting "return void" from a void function, as in C++, but I would expect returning anything else to generate a compile error.