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

Is it intended that Constructible<int&, long&>() is true? #301

Closed
timsong-cpp opened this issue Dec 5, 2016 · 4 comments
Closed

Is it intended that Constructible<int&, long&>() is true? #301

timsong-cpp opened this issue Dec 5, 2016 · 4 comments

Comments

@timsong-cpp
Copy link
Contributor

timsong-cpp commented Dec 5, 2016

__BindableReference is defined with a function-style cast expression, which is equivalent to a C-style cast in the single-argument case, which means it can degenerate to a reinterpret_cast or an access-bypassing static_cast.

Proposed Resolution

See P0547R1.

@timsong-cpp
Copy link
Contributor Author

The definitions of CommonReference and Common also use function-style casts with single arguments and so may potentially have the same issue.

@ericniebler
Copy link
Owner

This is almost certainly a bug. These concepts need help. Having spent some time trying to implement a conforming std::is_constructible, I've come to appreciate just how difficult it is to get all the corner cases right. I suspect we'll need compiler help for Constructible, or else define it in terms of the std::is_constructible.

Another approach is to do what is_constructible does and define it in terms of the well-formed-ness of the statement T tmp(args...); for some invented variable tmp. That leaves it up to implementers as to how it should be implemented.

@ericniebler
Copy link
Owner

At the very least, we should change the proposed definition of __BindableReference to the version in cmcstl2:

template <class T, class... Args>
concept bool __BindableReference = // exposition only
  is_reference<T>::value && is_constructible<T, Args...>::value;
};

And once we take that step, it's a short hop to:

template <class T, class... Args>
concept bool Constructible() {
  return Destructible<T>() && is_constructible<T, Args...>::value;
}

This would require us to change Destructible to permit reference and array types. This version of Constructible no longer requires object types to be dynamically allocate-able. We could add that or live with it. (Where do we need that?) On the plus side, Constructible would now always subsume Destructible.

@CaseyCarter let's try to figure this one out for Kona.

@CaseyCarter
Copy link
Collaborator

CopyConstructible requires Constructible<T, const T&>(), which currently requires the expression T{ct} to be valid for an invented lvalue const T variable ct. CopyConstructible need not explicitly require Constructible<T, T&>() and/or Constructible<T, const T&&>() since the expression T{ct} implicitly requires expression variants (per [concepts.lib.general.equality]/6) T{a} and T{b} to be valid for an invented lvalue T a and rvalue const T b. If the definition of Constructible changes to be "equivalent to is_constructible<...stuff...>" instead of using an expression requirement, then CopyConstructible will have to ensure those construction variants explicitly.

@ericniebler ericniebler added the P1 label Mar 3, 2017
@CaseyCarter CaseyCarter added review and removed new labels Mar 4, 2017
@ericniebler ericniebler added ready and removed review labels Jul 12, 2017
CaseyCarter added a commit that referenced this issue Jul 18, 2017
CaseyCarter added a commit that referenced this issue Jul 18, 2017
CaseyCarter added a commit that referenced this issue Jul 18, 2017
CaseyCarter added a commit that referenced this issue Jul 18, 2017
CaseyCarter added a commit that referenced this issue Jul 18, 2017
CaseyCarter added a commit that referenced this issue Jul 18, 2017
CaseyCarter added a commit that referenced this issue Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants