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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 29 - undefined behaviour of: scope(...){ return X; }
Summary: undefined behaviour of: scope(...){ return X; }
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords: accepts-invalid, EH
Depends on:
Blocks:
Reported: 2006年03月09日 15:11 UTC by Thomas Kühne
Modified: 2014年02月15日 02:08 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Thomas Kühne 2006年03月09日 15:11:22 UTC
void main(){
	scope(exit){
		return 0; // should fail to compile
	}
}
int main(){
	scope(exit){
		return 0; // undefined behaviour
	}
	return 1;
}
test cases:
http://dstress.kuehne.cn/nocompile/s/scope_08_A.d
http://dstress.kuehne.cn/nocompile/s/scope_08_C.d
http://dstress.kuehne.cn/nocompile/s/scope_08_B.d
http://dstress.kuehne.cn/undefined/scope_08_D.d
http://dstress.kuehne.cn/undefined/scope_08_E.d
http://dstress.kuehne.cn/undefined/scope_08_F.d 
Comment 1 Walter Bright 2006年03月09日 19:15:58 UTC
It shouldn't fail to compile. It means the same thing as a return inside a finally block. Not a bug.
Comment 2 Derek Parnell 2006年03月09日 19:44:17 UTC
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 Thomas Kühne 2006年03月10日 00:46:38 UTC
(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 Walter Bright 2006年06月20日 01:57:31 UTC
Fixed 0.161


AltStyle によって変換されたページ (->オリジナル) /