www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 29] New: undefined behaviour of: scope(...){ return X; }

reply d-bugmail puremagic.com writes:
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


-- 
Mar 09 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=29


walter digitalmars.com changed:

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





It shouldn't fail to compile. It means the same thing as a return inside a
finally block. Not a bug.


-- 
Mar 09 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=29






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"


-- 
Mar 09 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=29


thomas-dloop kuehne.cn changed:

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






 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 Thus the code below is illegal, yet compiles: --
Mar 09 2006