Bug 29 – undefined behaviour of: scope(...){ return X; }

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2006-03-09T15:11:00Z
Last change time
2014-02-15T02:08:20Z
Keywords
accepts-invalid, EH
Assigned to
bugzilla
Creator
thomas-dloop

Comments

Comment #0 by thomas-dloop — 2006-03-09T15:11:22Z
Comment #1 by bugzilla — 2006-03-09T19:15:58Z
It shouldn't fail to compile. It means the same thing as a return inside a finally block. Not a bug.
Comment #2 by ddparnell — 2006-03-09T19:44:17Z
But it *does* fail to compile now. For example, this program ... ------------------- import std.stdio; int Foo(int x) { scope(exit) if (x < 5) return x+9; return x; } void main() { for(int i = 0; i < 10; i++) writefln("IN %s OUT %s", i, Foo(i)); } ------------------- gives this compiler message ... "test.d(4): return statements cannot be in finally bodies"
Comment #3 by thomas-dloop — 2006-03-10T00:46:38Z
(In reply to comment #1) > It shouldn't fail to compile. It means the same thing as a return inside a > finally block. Not a bug. The correlation wiht finally isn't documented. http://www.digitalmars.com/d/statement.html#try # A FinallyStatement may not exit with a goto, break, continue, or # return; nor may it be entered with a goto. Thus the code below is illegal, yet compiles: # int test(){ # scope(exit) return 0; # } # void test(){ # scope(exit) return 0; # }
Comment #4 by bugzilla — 2006-06-20T01:57:31Z
Fixed 0.161