Thread overview
[Bug 29] New: undefined behaviour of: scope(...){ return X; }
Mar 09, 2006
d-bugmail
Mar 10, 2006
d-bugmail
Mar 10, 2006
d-bugmail
Mar 10, 2006
d-bugmail
March 09, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=29

           Summary: undefined behaviour of: scope(...){ return X; }
           Product: D
           Version: 0.149
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: accepts-invalid, EH
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: walter@digitalmars.com
        ReportedBy: thomas-dloop@kuehne.cn


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


-- 

March 10, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=29


walter@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from walter@digitalmars.com  2006-03-09 19:15 -------
It shouldn't fail to compile. It means the same thing as a return inside a finally block. Not a bug.


-- 

March 10, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=29





------- Comment #2 from ddparnell@bigpond.com  2006-03-09 19:44 -------
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"


-- 

March 10, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=29


thomas-dloop@kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




------- Comment #3 from thomas-dloop@kuehne.cn  2006-03-10 00:46 -------
(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;
# }


--