Skip to content

Commit 02b684a

Browse files
BVRazvanStudent USO VM User
andauthored
Fix Issue 20997 - Missing example of scope guard executing after return statement (#3520)
Co-authored-by: Student USO VM User <[email protected]>
1 parent 3b03d2a commit 02b684a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

spec/statement.dd

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,37 @@ $(CONSOLE
19831983
return; nor may it be entered with a goto. A $(D scope(failure))
19841984
statement may not exit with a return.
19851985

1986+
$(SPEC_RUNNABLE_EXAMPLE_RUN
1987+
--------------
1988+
import std.stdio;
1989+
1990+
int foo()
1991+
{
1992+
scope(exit) writeln("Inside foo()");
1993+
return bar();
1994+
}
1995+
1996+
int bar()
1997+
{
1998+
writeln("Inside bar()");
1999+
return 0;
2000+
}
2001+
2002+
int main()
2003+
{
2004+
foo();
2005+
return 0;
2006+
}
2007+
--------------
2008+
)
2009+
2010+
writes:
2011+
2012+
$(CONSOLE
2013+
Inside bar()
2014+
Inside foo()
2015+
)
2016+
19862017
$(H3 $(LNAME2 catching_cpp_class_objects, Catching C++ Class Objects))
19872018

19882019
$(P

0 commit comments

Comments
 (0)