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

STL: "Effects: Equivalent to" implies Constraints #214

Closed
StephanTLavavej opened this issue Oct 25, 2019 · 0 comments · Fixed by #2607
Closed

STL: "Effects: Equivalent to" implies Constraints #214

StephanTLavavej opened this issue Oct 25, 2019 · 0 comments · Fixed by #2607
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@StephanTLavavej
Copy link
Member

The Standard frequently uses "Effects: Equivalent to" when specifying things. This is awesome because it provides an implementation that can be used in production code, nearly unchanged, 99% of the time. (Occasionally, a more efficient implementation is possible.)

For example, shared_ptr's assignment from unique_ptr is specified as:

Effects: Equivalent to shared_­ptr(std​::​move(r)).swap(*this).

However, shared_ptr's constructor from unique_ptr is constrained (currently with old-style wording):

Remarks: This constructor shall not participate in overload resolution unless Y* is compatible with T* and unique_­ptr<Y, D>​::​pointer is convertible to element_­type*.

Finally, the Standard's Library-wide wording says:

Whenever the Effects element specifies that the semantics of some function F are Equivalent to some code sequence, then the various elements are interpreted as follows. If F's semantics specifies any Constraints or Mandates elements, then those requirements are logically imposed prior to the equivalent-to semantics.

We've never implemented that. For example, we constrain the constructor:

STL/stl/inc/memory

Lines 1109 to 1113 in 6b0238d

template <class _Ux, class _Dx,
enable_if_t<conjunction_v<_SP_pointer_compatible<_Ux, _Ty>,
is_convertible<typename unique_ptr<_Ux, _Dx>::pointer, element_type*>>,
int> = 0>
shared_ptr(unique_ptr<_Ux, _Dx>&& _Other) {

But we don't constrain the assignment operator:

STL/stl/inc/memory

Lines 1162 to 1166 in 6b0238d

template <class _Ux, class _Dx>
shared_ptr& operator=(unique_ptr<_Ux, _Dx>&& _Right) { // move from unique_ptr
shared_ptr(_STD move(_Right)).swap(*this);
return *this;
}

This is a bug because the difference is detectable through is_assignable.

The extent of this problem is unknown. I don't know of a better way to thoroughly fix this issue than going through every occurrence of "Effects: Equivalent to" in the Standard and looking for expressions that involve constrained machinery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant