Skip to content

[class.cdtor] explicitly invoking a destructor from a constructor CWG2757 #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sergey-anisimov-dev opened this issue Sep 27, 2023 · 6 comments

Comments

@sergey-anisimov-dev
Copy link

Full name of submitter (unless configured in github; will be published with the issue): Sergey Anisimov

Reference (section label): [class.cdtor]

Issue description: Basically, CWG2757 doesn't address the issue normatively, only informatively: it mentions using a delete-expr or reusing/releasing the storage for the object, while an explicit destructor call constitutes neither. The intention is there though, apparently, since the example supplemented features such a situation.

Suggested resolution: Insert , invoking a destructor for the object between evaluating a delete-expression with an operand that points to the object and or releasing or reusing (6.7.3 [basic.life]) the storage which the object occupies within the normative part of the resolution already proposed.

@frederick-vs-ja
Copy link

It might be simpler to add the prohibition to [class.cdtor] p4.

@sergey-anisimov-dev
Copy link
Author

It might be simpler to add the prohibition to [class.cdtor] p4.

Might be a valid consideration. It's just that presently that clause is centered around the infamous static binding of the virtual functions in constructors/destructors. It might just be better to leave it be and group somewhat-related operations of "free"/"delete"/"destroy" together as CWG2757 originally intends.
I personally would likely prefer seeing the prohibition of invoking the destructors explicitly stated rather than referred to in an obscure manner like Member functions, including virtual functions [class.virtual], except for the destructors, can be called during construction or destruction [class.base.init], as this is a double inversion: calling non-static member functions in out-of-life situations is generally disallowed by [basic.life#6.2]/[basic.life#7.2], then we state that it's ok only to disallow it specifically for the destructors just a couple of words after. On the other hand, this would be less contradictive: current resolution would disallow calling them specifically before explicitly reallowing a more generic action two clauses down... Perhaps it would indeed be better to state this in some other way after all.

@jensmaurer
Copy link
Member

This seems to be pointing to a defect in the suggested wording for CWG2757. I've amended the suggested wording.
(A delete-expression invokes the destructor.)

@sergey-anisimov-dev
Copy link
Author

I'll just leave a note on the fact that this supposedly allows for delete-exprs that resolve into a destroying-delete (neither the destructor calls, nor the storage reuses/releases are guaranteed under such circumstances: the behavior is user-defined). This most likely isn't a problem though for the very same reasons.

@languagelawyer
Copy link

languagelawyer commented Oct 2, 2023

I think, given

During the construction or destruction of an object, invoking the destructor for the object … is undefined behavior.

http://eel.is/c++draft/class.dtor#18 can be completely removed, because, during construction/destruction, this is covered by the newly-proposed wording, and by http://eel.is/c++draft/basic.life#6.2 / http://eel.is/c++draft/basic.life#7.2 otherwise
(plus http://eel.is/c++draft/basic.life#1.4 says the lifetime ends)

(OTOH, as it is known, http://eel.is/c++draft/class.dtor#18 conflicts with http://eel.is/c++draft/basic.life#9.sentence-1 a bit, in «non-trivial destructor» requirement)

@sergey-anisimov-dev
Copy link
Author

That is the idea: perhaps you would be interested in reviewing this issue, @languagelawyer (especially concerning [basic.life#9]).

@jensmaurer jensmaurer changed the title [class.cdtor] explicitly invoking a destructor from a constructor [class.cdtor] explicitly invoking a destructor from a constructor CWG2757 Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants