microsoft / microsoft/STL

`<ranges>`: `elements_view::iterator::iterator_category` invokes the `operator*() &&` of the underlying iterator

Open
#3,031 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug ranges
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

https://github.com/microsoft/STL/blob/b812b0e22b6e2a777800c6080ab636d70aec0678/stl/inc/ranges#L4982-L4989

Should _STD declval<iterator_t<_Base>>() be _STD declval<const iterator_t<_Base>&>()?

#include <ranges>

struct I {
  using difference_type = std::ptrdiff_t;
  using value_type = std::pair<int, double>;
  value_type& operator*() const &;
  void operator*() && = delete;
  I& operator++();
  I operator++(int);
  bool operator==(const I&) const;
};

int main() {
  std::ranges::input_range auto r = std::ranges::subrange(I{}, std::unreachable_sentinel);
  auto e = r | std::views::keys;
}

https://godbolt.org/z/oW8dP56zv

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

Start at stl/inc/ranges around lines 4982-4989 and reproduce the issue with the provided iterator and views::keys example on Compiler Explorer. Inspect how elements_view::iterator derives iterator_category, then verify the corrected behavior with the example and relevant ranges tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.