[Issue 2214] New: No error if void function returns a value
Jarrett Billingsley
kb3ctd2 at yahoo.com
Thu Jul 10 12:03:41 PDT 2008
<d-bugmail at puremagic.com> wrote in message
news:bug-2214-3 at http.d.puremagic.com/issues/...
> http://d.puremagic.com/issues/show_bug.cgi?id=2214
>
> Summary: No error if void function returns a value
> Product: D
> Version: unspecified
> Platform: PC
> OS/Version: Windows
> Status: NEW
> Keywords: accepts-invalid
> Severity: normal
> Priority: P2
> Component: DMD
> AssignedTo: bugzilla at digitalmars.com
> ReportedBy: 2korden at gmail.com
>
>
> 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?
I think it's by design. It's come in very handy in a lot of generic code
I've written. I.e. if I write a function which wraps another function, I
don't have to do an icky test to see if the return type is void or not, and
decide whether or not to "return realFunction();". I just have a single
codepath that works for void functions and non-void functions.
More information about the Digitalmars-d-bugs
mailing list