Skip to content

[unique.ptr.create] std::make_unique<int&> may not be rejected properly #7009

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

Closed
Eisenwave opened this issue May 15, 2024 · 3 comments
Closed

Comments

@Eisenwave
Copy link
Contributor

std::make_unique<int&> is not rejected by a Constraints or Mandates specification. Instead, it is said to return

unique_ptr<T>(new T(std​::​forward<Args>(args)...))

... and this would be ill-formed when T is a reference type, function type, etc. std::unique_ptr<T> is also allowed for basically any T (including incomplete types such as void); you just need the right deleter to make it work.

I believe this could be solved editorially be using an Equivalent to specification instead of a Returns specification. Any opinions?

@Eisenwave
Copy link
Contributor Author

Eisenwave commented May 15, 2024

While we're at it, I believe that std::make_shared is similarly under-constrained, but I'm not sure if we wold want to solve it in the same way.

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented May 16, 2024

I guess it's redundant to specify them like this:

  • Mandates: expr is well-formed.
  • Returns: expr.

"Equilvalent to" propagates Constraints, which would be a bit problematic when arbitrary T is involved. See LWG3628.

@Eisenwave
Copy link
Contributor Author

Makes sense. There is also the alternative of copying over the "mandates" for new-expressions to be used: https://eel.is/c++draft/expr.new#1.sentence-3

If it was as simple as

Mandates: T is a complete object type.

... I would have seen it as a slight net positive, but the rules aren't as simple, and this is just more wording that needs to be kept in sync. I think it should be left as is; I don't see a way to improve it for std::make_unique at least.

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

2 participants