microsoft / microsoft/STL

<span>: checked iterators became too intolerant

Open
#1,435 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

LWG issue needed
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Describe the bug
Checked iterators controlled by _ITERATOR_DEBUG_LEVEL provide some safe guarantee, but these assertions became more and more intolerant for programming in normal styles.

Command-line test case

std::array<std::byte, 10> a{};
std::span<std::byte> s1 = a;
std::span<std::byte> s2 = s1.subspan(1);
std::cout << s2.begin() - s1.begin(); // assertion failed while _ITERATOR_DEBUG_LEVEL >= 1

Expected behavior
Both these two span s1 and s2 came from a, hence they share the same underlying sequence.
I think this design makes iterators of the same type pointing to the same element not equivalent. (may be an LWG issue?)
From a programmer’s point of view, the code snippet above is a common requirement, especially when parsing certain data.

STL version

Microsoft Visual Studio Community 2019
Version 16.7.7

Contributor guide

Open the contributing guide

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

Reproduce the command-line case with _ITERATOR_DEBUG_LEVEL >= 1, focusing on std::span::begin() and checked-iterator subtraction. The issue is done when this same-sequence operation no longer asserts, with behavior covered by a regression test; no file or test path is named in the report.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.