cplusplus / cplusplus/draft

[unique.ptr.general] Intro wording is misleadingly restrictive

Open
#7,015 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3-Other
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

https://eel.is/c++draft/unique.ptr.general#1 (and remaining) paragraphs make overly restrictive claims:

  • a unique pointer owns an object
  • a unique pointer stores a pointer

Neither of these claims are necessarily true. The following program is valid, and compiles with libc++:

#include <memory>

struct deleter {
    using pointer = int(*)();
    void operator()(pointer) const {}
};

int main() {
    std::unique_ptr<int&, deleter> ptr;
    ptr.get();
}
  • What is the owned object here? Neither int& nor int() are objects types.
  • While pointer is actually a pointer in this example, it is generally any pointer-like type that satisfies NullablePointer. It's not required to be a pointer.

I think it's all arguably not a big problem, and this is simply questionable wording in the semi-normative intro paragraphs. However, it's also not nice that the wording is making claims that get contradicted/superseded/corrected by later wording. It would be nice if this wasn't the case.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked unique.ptr.general section and read the introductory and remaining paragraphs together, then compare their descriptions with the NullablePointer requirements and the example in the issue. Done means the introductory wording no longer makes claims contradicted by the later specification; the issue does not name a repository file or test to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.