Bug 20394 – "one path skips constructor" when exception is thrown

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-11-15T13:07:56Z
Last change time
2024-12-13T19:06:13Z
Assigned to
No Owner
Creator
Piotr Mitana
Moved to GitHub: dmd#17928 →

Comments

Comment #0 by piotr.mitana — 2019-11-15T13:07:56Z
struct X { this(int a) { if(a == 0) this(a, 1); else throw new Exception(""); } this(int a, int b) {} } The code above fails to compile with "one path skips constructor" error. It can be worked around by adding "assert(0);" to the else block, but shoudn't throwing exception be enough?
Comment #1 by dkorpel — 2019-11-15T14:00:09Z
An exception represents a recoverable error that can be caught and then you end up with a partially constructed object. An assert(0) represents an unrecoverable error, the state of the program afterwards is undefined so partially constructed objects are possible. To me the error seems appropriate.
Comment #2 by robert.schadek — 2024-12-13T19:06:13Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17928 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB