cplusplus / cplusplus/draft

[unreachable.sentinel] Incorrect usage example of std::unreachable_sentinel

Open
#7,859 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

An incorrect description of an example was spotted on Stack Overflow (the comment under the question), [unreachable.sentinel] p2 says:

[Example 1 :

char* p;
// set p to point to a character buffer containing newlines
char* nl = find(p, unreachable_sentinel, '\n');

Provided a newline character really exists in the buffer, the use of unreachable_sentinel above potentially makes
the call to find more efficient since the loop test against the sentinel does not require a conditional branch. — end
example
]

The description says that the example is well-defined if a null character is reachable from p, but std::ranges::find requires the input range to be valid, as [iterator.requirements.general] p12 says:

The result of the application of library functions to invalid ranges is undefined.

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

Read the [unreachable.sentinel] p2 example alongside [iterator.requirements.general] p12, which the issue cites. Confirm how the example's range validity requirement affects its description, then update the standard draft wording so the example does not claim validity under an insufficient condition.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.