Bug 14734 – Throwing a nested class should not be legal

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-06-25T14:59:54Z
Last change time
2024-12-13T18:43:35Z
Assigned to
No Owner
Creator
Mathias LANG
Moved to GitHub: dmd#17714 →

Comments

Comment #0 by pro.mathias.lang — 2015-06-25T14:59:54Z
Throwing a nested Exception has the potential to trigger memory errors, as it is not guaranteed that the context object will outlive the Exception. Given Exceptions' nature, and unless the GC is used, it's actually more likely that it won't. Example: ```` import std.stdio; enum LoremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse ci\ llum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; class Foo { char[LoremIpsum.length] str; class LocalException : Exception { void print() @safe { this.outer.str[] = LoremIpsum[]; writeln(this.outer.str); } public this(string msg, string f = __FILE__, int l = __LINE__) @safe nothrow { super(msg, f, l); } } void act() @safe { throw new LocalException("Oops"); } } void bar() @safe { scope baz = new Foo(); baz.act(); } void main() @safe { try bar(); catch (Foo.LocalException e) { "Catched".writeln; e.print(); "Foobar".writeln; } } ```` This triggers a segmentation fault.
Comment #1 by robert.schadek — 2024-12-13T18:43:35Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17714 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB