[Issue 3922] Wrong error message with return in void function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 14 05:23:36 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=3922


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |
           Severity|normal                      |enhancement


--- Comment #7 from bearophile_hugs at eml.cc 2011-06-14 05:18:56 PDT ---
Reopened as enhancement request after discussions in bug 3746.

This is from the DMD 2.053 specs:
http://www.digitalmars.com/d/2.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. If the Expression
has no side effects, and the return type is void, then it is illegal.


So according to the D specs this code is illegal:

pure int sqr(int x) { return x * x; }
void main() {
    return sqr(10);
}


While this code is correct:

int sqr(int x) { return x * x; }
void main() {
    return sqr(10);
}

But I can't see this as correct, it's bug prone. I think it's better to turn
into an error returning any nonvoid from a void function, regardless of side
effects.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list