D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3478 - "no effect in expression" error on return to void
Summary: "no effect in expression" error on return to void
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Linux
: P2 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-05 16:26 UTC by Moritz Warning
Modified: 2014-04-18 09:12 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Moritz Warning 2009-11-05 16:26:18 UTC
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 Walter Bright 2009-11-05 18:55:45 UTC
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 Moritz Warning 2009-11-05 19:21:30 UTC
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 Moritz Warning 2009-11-05 19:23:17 UTC
fwiw, the new behavior makes sense to me.
Comment 4 Don 2009-11-05 21:42:48 UTC
(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 Walter Bright 2009-11-30 02:31:19 UTC
I'll change the spec to say that it's illegal to have a void return expression with no side effects.
Comment 6 Walter Bright 2009-12-06 00:54:03 UTC
Fixed dmd 2.037