[Issue 5399] Return the result of a nonvoid function in a void function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 1 23:02:13 PST 2011


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


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


--- Comment #1 from bearophile_hugs at eml.cc 2011-01-01 23:00:02 PST ---
This isn't a bug, I was wrong. D2 specs clearly show this is working as
expected:
http://www.digitalmars.com/d/2.0/statement.html

ReturnStatement:
    return;
    return Expression ;

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.


Indeed, this too compiles:

void main() {
    int x;
    return x++;
}


But this is a potentially dangerous corner case in the return rules.

-- 
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