Skip to content
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

[containers] Tentative P/R for [LWG4123] "Container effects use..." #7207

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Quuxplusone
Copy link
Contributor

Attn @jwakely. This PR isn't editorial; it's for LWG editor's benefit. I'll turn it into a "Draft" ASAP, if GitHub lets me do that.

https://cplusplus.github.io/LWG/issue4123

The superficial problem here is that "assignment operator or move assignment operator" is redundant. The real problem is that the container might use an assignment operator that's not a copy-or-move assignment operator, and/or a constructor that's not a copy-or-move constructor.

We want to preserve the idea of "constructing or assigning a T from another T," as opposed to from a U. But we want to permit all the various ways of doing that, such as "implicitly convert the source T to U, then assign from U to T," as shown in this Godbolt: https://godbolt.org/z/8Ybbxr19e
(If one of those various ways throws, then there might be effects, even though the throwing culprit wasn't a constructor or assignment operator of T at all.)

We have similar problems in [optional], e.g.
https://eel.is/c++draft/optional.optional#optional.ctor-6
"Any exception thrown by the selected constructor of T."
(Overload resolution might select a conversion operator, not a constructor.)
https://eel.is/c++draft/optional.optional#optional.assign-7
"If an exception is thrown during the call to T's copy constructor, no effect.
If an exception is thrown during the call to T's copy assignment, the state
of its contained value is as defined by the exception safety guarantee of T's
copy assignment."
(Overload resolution might select a constructor that is not a copy constructor,
resp. an assignment [operator] that is not a copy assignment operator.)

I have not attempted to fix those problems in this patch.

@Quuxplusone Quuxplusone marked this pull request as draft August 8, 2024 19:27
https://cplusplus.github.io/LWG/issue4123

The superficial problem here is that "assignment operator or move assignment operator"
is redundant. The real problem is that the container might use an assignment operator
that's not a copy-or-move assignment operator, and/or a constructor that's not
a copy-or-move constructor.

We want to preserve the idea of "constructing or assigning a T from another T,"
as opposed to from a U. But we want to permit all the various ways of doing that,
such as "implicitly convert the source T to U, then assign from U to T," as shown
in this Godbolt: https://godbolt.org/z/8Ybbxr19e
(If one of those various ways throws, then there might be effects, even though
the throwing culprit wasn't a constructor or assignment operator of `T` at all.)

We have similar problems in [optional], e.g.
https://eel.is/c++draft/optional.optional#optional.ctor-6
 "Any exception thrown by the selected constructor of T."
 (Overload resolution might select a conversion operator, not a constructor.)
https://eel.is/c++draft/optional.optional#optional.assign-7
 "If an exception is thrown during the call to T's copy constructor, no effect.
 If an exception is thrown during the call to T's copy assignment, the state
 of its contained value is as defined by the exception safety guarantee of T's
 copy assignment."
 (Overload resolution might select a constructor that is not a copy constructor,
 resp. an assignment [operator] that is not a copy assignment operator.)

I have not attempted to fix those problems in this patch.
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

Successfully merging this pull request may close these issues.

1 participant