www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13217] New: nothrow, template function and delegate:

https://issues.dlang.org/show_bug.cgi?id=13217

          Issue ID: 13217
           Summary: nothrow, template function and delegate: compilation
                    error
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: villytiger gmail.com

$ cat main.d
import std.stdio;

nothrow void a(T)(T x) {
        try {
                () {
                writeln("a");
                } ();
        } catch(Exception e) {
        }
}

void main() {
        a(1);
}
$ dmd main.d
main.d(6): Error: 'std.stdio.writeln!(string).writeln' is not nothrow
main.d(5): Error: delegate 'main.a!int.a.__lambda2' is nothrow yet may throw
main.d(13): Error: template instance main.a!int error instantiating

Any of the following actions remove error:
- moving nothrow to the end of function declaration
- making function without template
- calling writeln directly without delegate

$ cat main.d
import std.stdio;

void a() nothrow {
        try {
                writeln("a");
        } catch(Exception e) {
        }
}

void main() {
        a();
}
$ dmd main.d
$ echo $?
0

--
Jul 27 2014