www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20997] New: Missing example of scope guard executing after

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

          Issue ID: 20997
           Summary: Missing example of scope guard executing after return
                    statement
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dlang.org
          Assignee: nobody puremagic.com
          Reporter: simen.kjaras gmail.com

As pointed out on the forum[0], the documentation[1] for scope guards should
include an example with a return statement. Something like this:

import std.stdio;

int fun() {
    scope (exit) writeln("Scope guard");
    return gun();
}

int gun() {
    writeln("Inside gun()");
    return 3;
}

Will print:

Inside gun()
Scope guard


[0]: https://forum.dlang.org/thread/qzhhdjqvjxsycuxjdefo forum.dlang.org
[1]: https://dlang.org/spec/statement.html#scope-guard-statement

--
Jun 30