GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

libstdc++ ranges::mismatch returns correct iterator type.

The ranges::mismatch function in libstdc++ now returns the correct iterator type as specified by the standard.

The C++ standard library’s implementation of ranges::mismatch in libstdc++ has been corrected to return the borrowed_iterator_t type. This ensures consistency with the standard’s specification and prevents potential issues with dangling iterators in certain use cases. A new test case verifies this fix.

In Details

The <ranges> library in C++20 introduces various algorithms. For algorithms like mismatch that return iterators, the standard specifies using std::ranges::borrowed_iterator_t<I> for the return type to correctly handle iterators that might become invalidated after the algorithm returns. This commit updates the ranges::mismatch implementation in libstdc++ to adhere to this, fixing a deviation from the standard.

For Context
ranges::mismatch
A C++20 algorithm that compares two ranges element by element and returns a pair of iterators pointing to the first differing elements.
borrowed_iterator_t
A C++20 type trait that determines the appropriate iterator type to return from a ranges algorithm, ensuring it's not a dangling reference.
libstdc++
The standard C++ library implementation used by GCC.
Filed Under: libstdc++c++20ranges