Thread overview
[Issue 22177] emplace should handle throwing constructors
Aug 04, 2021
kinke
Aug 04, 2021
kinke
Aug 04, 2021
kinke
Nov 27, 2021
Stanislav Blinov
Nov 27, 2021
Stanislav Blinov
Dec 17, 2022
Iain Buclaw
August 04, 2021
https://issues.dlang.org/show_bug.cgi?id=22177

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #1 from kinke <kinke@gmx.net> ---
Works since v2.096.

--
August 04, 2021
https://issues.dlang.org/show_bug.cgi?id=22177

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #2 from kinke <kinke@gmx.net> ---
Dammit, wrong tab. ;)

--
August 04, 2021
https://issues.dlang.org/show_bug.cgi?id=22177

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |NEW

--
November 27, 2021
https://issues.dlang.org/show_bug.cgi?id=22177

Stanislav Blinov <stanislav.blinov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |stanislav.blinov@gmail.com

--- Comment #3 from Stanislav Blinov <stanislav.blinov@gmail.com> ---
I think the language should specify (as in, explicitly state in the spec) the expected state of an object in case its ctor throws. IMO it should be the user's job to leave their objects in a destructible state.

Perhaps something like: "If a constructor throws an exception, the object MAY still be destructed. Therefore, constructors should always leave objects in a destructible state."

Pseudo-code for emplace is:

emplaceInitializer(ptr);
constructAt(ptr, args);

Thus it makes little sense to write the initializer again. User was given a piece of memory, it's theirs now to keep tidy. It follows then that it should be the user's responsibility to maintain exception safety in their ctors.

An outlier here is emplacement of arrays, where it does make sense to write .init into the remainder of array if an exception was thrown, as that *is* assumed to contain garbage state.

Overwriting partially-constructed state with .init can potentially be problematic sine can cause resource leaks.

--
November 27, 2021
https://issues.dlang.org/show_bug.cgi?id=22177

--- Comment #4 from Stanislav Blinov <stanislav.blinov@gmail.com> ---
*since it can. Typing before coffee...

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=22177

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 07
https://issues.dlang.org/show_bug.cgi?id=22177

--- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17426

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--