Skip to content

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

Open
@xmcgcg

Description

@xmcgcg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lwgIssue must be reviewed by LWG.not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions