https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122842
Bug ID: 122842
Summary: Compiler crash when passing std::ranges::cbegin to a
function with std::ranges::const_iterator_t as a
template parameter
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: eidhne.kennedy at gmail dot com
Target Milestone: ---
Attempting to pass a `std::ranges::const_iterator_t` as a template parameter
fails when `std::ranges::cbegin` is passed to the function.
```c++
#include <iterator>
#include <ranges>
#include <string>
template<std::input_iterator IT_T>
void some_function(IT_T)
{
}
int main(void) {
std::string someString;
some_function<std::ranges::const_iterator_t<std::string>>(std::ranges::cbegin(someString));
}
```
causes the compiler to fail with the following output:
```
<source>: In function 'int main()':
<source>:13:81: error: could not convert
'std::ranges::_Cpo::cbegin.std::ranges::__access::_CBegin::operator()<std::__cxx11::basic_string<char>&>(someString)'
from '__gnu_cxx::__normal_iterator<const char*,
std::__cxx11::basic_string<char> >' to
'std::basic_const_iterator<__gnu_cxx::__normal_iterator<char*,
std::__cxx11::basic_string<char> > >'
13 |
some_function<std::ranges::const_iterator_t<std::string>>(std::ranges::cbegin(someString));
|
~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
|
|
|
__gnu_cxx::__normal_iterator<const char*,
std::__cxx11::basic_string<char> >
Compiler returned: 1
```
with the flags `-std=c++23 -O3`
note that adding const to the variable and the `const_iterator_t` type results
in the program compiling as expected
```c++
#include <iterator>
#include <ranges>
#include <string>
template<std::input_iterator IT_T>
void some_function(IT_T)
{
}
int main(void) {
std::string const someString;
some_function<std::ranges::const_iterator_t<std::string
const&>>(std::ranges::cbegin(someString));
}
```