Bug 3478 – "no effect in expression" error on return to void

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Linux
Creation time
2009-11-05T16:26:00Z
Last change time
2014-04-18T09:12:08Z
Assigned to
nobody
Creator
moritzwarning

Comments

Comment #0 by moritzwarning — 2009-11-05T16:26:18Z
void foo() { return 0; } this code gives main.d(24): Error: long has no effect in expression (0) iirc, it should be valid.
Comment #1 by bugzilla — 2009-11-05T18:55:45Z
I'd actually like that to be the new behavior, as any other behavior (I tried them) caused worse problems. The good news is it's an easy fix for the code.
Comment #2 by moritzwarning — 2009-11-05T19:21:30Z
You should change the spec in this case: http://www.digitalmars.com/d/1.0/statement.html "Expression is allowed even if the function specifies a void return type. The Expression will be evaluated, but nothing will be returned."
Comment #3 by moritzwarning — 2009-11-05T19:23:17Z
fwiw, the new behavior makes sense to me.
Comment #4 by clugdbug — 2009-11-05T21:42:48Z
(In reply to comment #2) > You should change the spec in this case: > > http://www.digitalmars.com/d/1.0/statement.html > > > "Expression is allowed even if the function specifies a void return type. The > Expression will be evaluated, but nothing will be returned." It's still true. This works, for example: void foo() { return bar(); } It's exactly the same as: { bar(); return; } which is OK. Likewise, return 0; becomes { 0; return; } which is generating the "no effect" error.
Comment #5 by bugzilla — 2009-11-30T02:31:19Z
I'll change the spec to say that it's illegal to have a void return expression with no side effects.
Comment #6 by bugzilla — 2009-12-06T00:54:03Z
Fixed dmd 2.037