https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94164
Bug ID: 94164 Summary: [Regression 10] std::unintialized_fill_n fails to compile Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: laurent.stacul at gmail dot com Target Milestone: --- Hello, I have this piece of code: #include <memory> template<typename T> struct ref { typedef T value_type; typedef T* pointer; typedef T& reference; typedef ptrdiff_t difference_type; typedef std::random_access_iterator_tag iterator_category; int d; explicit ref(int =0): d(-1) {} operator pointer() { if (d == -1) { return 0; } else { return reinterpret_cast<pointer>(this + d); } } ref& operator++() { d += sizeof(value_type); return *this; } }; int main(int, const char *[]) { ref<char> r; std::uninitialized_fill_n(r, 10, 'a'); return 0; } I compile it with the following command (the -std option is not important): $ g++ -Wall -Wextra -std=gnu++2a -c -o main.o main.cpp When I compile it with gcc (GCC) 10.0.1 20200305, if fails with the following error: /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h: In instantiation of 'constexpr _OutputIterator std::__fill_n_a(_OutputIterator, _Size, const _Tp&, std::random_access_iterator_tag) [with _OutputIterator = ref<char>; _Size = int; _Tp = char]': /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h:1085:29: required from 'constexpr _OI std::fill_n(_OI, _Size, const _Tp&) [with _OI = ref<char>; _Size = int; _Tp = char]' /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_uninitialized.h:254:29: required from 'static _ForwardIterator std::__uninitialized_fill_n<true>::__uninit_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = ref<char>; _Size = int; _Tp = c har]' /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_uninitialized.h:289:17: required from '_ForwardIterator std::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = ref<char>; _Size = int; _Tp = char]' main.cpp:32:41: required from here /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h:1056:20: error: no matching function for call to '__fill_a(ref<char>&, ref<char>::pointer, const char&)' 1056 | std::__fill_a(__first, __first + __n, __value); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h:904:5: note: candidate: 'template<class _FIte, class _Tp> constexpr void std::__fill_a(_FIte, _FIte, const _Tp&)' 904 | __fill_a(_FIte __first, _FIte __last, const _Tp& __value) | ^~~~~~~~ /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h:904:5: note: template argument deduction/substitution failed: /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h:1056:20: note: deduced conflicting types for parameter '_FIte' ('ref<char>' and 'char*') 1056 | std::__fill_a(__first, __first + __n, __value); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h:909:5: note: candidate: 'template<class _Ite, class _Seq, class _Cat, class _Tp> void std::__fill_a(const __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&, const __gnu_debug::_Safe_iterator<_Ite, _Seq , _Cat>&, const _Tp&)' 909 | __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&, | ^~~~~~~~ /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h:909:5: note: template argument deduction/substitution failed: /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h:1056:20: note: 'ref<char>' is not derived from 'const __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>' 1056 | std::__fill_a(__first, __first + __n, __value); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /x86_64-v20.0.13/include/c++/10.0.1/bits/stl_algobase.h:1057:22: error: could not convert '(__first.ref<char>::operator ref<char>::pointer() + ((sizetype)__n))' from 'ref<char>::pointer' {aka 'char*'} to 'ref<char>' 1057 | return __first + __n; | ~~~~~~~~^~~~~ | | | ref<char>::pointer {aka char*} make: *** [Makefile:6: main.o] Error 1 Conversely, this code compiles with gcc (GCC) 9.2.1. Maybe is it related to https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=6004c17b4d1a2dd1e1936b2e705a5ccfb6e48ab2 but I don' t know if the current bahviour is expected. Stac