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
It shouldn't fail to compile. It means the same thing as a return inside a finally block. Not a bug.
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"
(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; # }
Fixed 0.161
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル