Bug 8150 – Throwing nothrow struct constructor?

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-25T13:56:00Z
Last change time
2012-09-25T07:04:01Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-05-25T13:56:47Z
This compiles with no errors: struct Foo { this(int) nothrow { throw new Exception("something"); } } void main() { Foo(1); } DMD 2.060alpha gives at run-time: [email protected](3): something
Comment #1 by k.hara.pg — 2012-09-22T22:22:46Z
Comment #2 by github-bugzilla — 2012-09-22T23:43:35Z
Commit pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/cd1252036b41533ba5b132c99471e84d468d1f0b Making Throwable and derived classes constructors @safe/pure/nothrow. This is supplemental change for fixing issue 8150. Constructing throwable object can be @sage, pure, and nothrow.
Comment #3 by github-bugzilla — 2012-09-24T07:47:09Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/c519a4d9dcc8b65aaadba2f30fdecf63bec5df99 fix Issue 8150 - Throwing nothrow struct constructor? https://github.com/D-Programming-Language/dmd/commit/36e0a9b975941aac4bf5bd6fd044e6acbf2504e9 Merge pull request #1138 from 9rnsr/fix8150 Issue 8150 - Throwing nothrow struct constructor?
Comment #4 by bearophile_hugs — 2012-09-24T09:50:47Z
Now compiling this code: struct Foo { this(int) nothrow { // line 2 throw new Exception("something"); } } void main() { Foo(1); } It gives: temp.d(3): Error: object.Exception is thrown but not caught temp.d(2): Warning: statement is not reachable temp.d(2): Error: constructor temp.Foo.this 'this' is nothrow yet may throw What's the statement not not reachable at line 2?
Comment #5 by monarchdodra — 2012-09-24T22:59:42Z
Could you also check that a nothrow constructor can still throw an Error please? From related: http://d.puremagic.com/issues/show_bug.cgi?id=8675
Comment #6 by k.hara.pg — 2012-09-25T06:51:38Z
(In reply to comment #4) > Now compiling this code: > > struct Foo { > this(int) nothrow { // line 2 > throw new Exception("something"); > } > } > void main() { > Foo(1); > } > > > It gives: > > temp.d(3): Error: object.Exception is thrown but not caught > temp.d(2): Warning: statement is not reachable > temp.d(2): Error: constructor temp.Foo.this 'this' is nothrow yet may throw > > What's the statement not not reachable at line 2? This is diagnostic bug. I've opened new bug 8724.
Comment #7 by k.hara.pg — 2012-09-25T06:56:50Z
(In reply to comment #5) > Could you also check that a nothrow constructor can still throw > an Error please? > > From related: http://d.puremagic.com/issues/show_bug.cgi?id=8675 Nothrow check mechanism for the constructors is same as for normal functions, and that's already fixed by 8675. So, there is no problem.
Comment #8 by monarchdodra — 2012-09-25T07:04:01Z
(In reply to comment #7) > (In reply to comment #5) > > Could you also check that a nothrow constructor can still throw > > an Error please? > > > > From related: http://d.puremagic.com/issues/show_bug.cgi?id=8675 > > Nothrow check mechanism for the constructors is same as for normal functions, > and that's already fixed by 8675. So, there is no problem. Ok, thanks. Just double checking: wouldn't want to re-introduce a bug :)