Thread overview
[Issue 1975] New: void func return value not checked
Apr 05, 2008
d-bugmail
Apr 06, 2008
d-bugmail
April 05, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1975

           Summary: void func return value not checked
           Product: D
           Version: 2.012
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: someanon@yahoo.com


should raise a warning/ or error:

$ cat voidreturn.d
void f() {
  return 1;
}

$ dmd -c -w voidreturn.d


-- 

April 05, 2008
<d-bugmail@puremagic.com> wrote in message news:bug-1975-3@http.d.puremagic.com/issues/...
> http://d.puremagic.com/issues/show_bug.cgi?id=1975
>
>           Summary: void func return value not checked
>           Product: D
>           Version: 2.012
>          Platform: PC
>        OS/Version: Linux
>            Status: NEW
>          Severity: normal
>          Priority: P2
>         Component: DMD
>        AssignedTo: bugzilla@digitalmars.com
>        ReportedBy: someanon@yahoo.com
>
>
> should raise a warning/ or error:
>
> $ cat voidreturn.d
> void f() {
>  return 1;
> }
>
> $ dmd -c -w voidreturn.d

It's legal for various reasons, the main one being templated programming. It avoids special-casing returns for void functions.  I've used it more than once.  If a function is 'void', then "return x" is basically the same as "x; return", as long as x can be evaluated.


April 06, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1975


matti.niemenmaa+dbugzilla@iki.fi changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from matti.niemenmaa+dbugzilla@iki.fi  2008-04-06 04:12 -------
This is quite intentional. http://digitalmars.com/d/2.0/statement.html#ReturnStatement says: "Expression is allowed even if the function specifies a void return type. The Expression will be evaluated, but nothing will be returned."


--