On Tue, 16 Jan 2024 at 15:39, Jonathan Wakely <jwak...@redhat.com> wrote: > > On Tue, 16 Jan 2024 at 14:07, Jonathan Wakely wrote: > > > > On 15/01/24 19:09 -0500, Patrick Palka wrote: > > >> + friend _Iterator > > >> + operator+(_Iterator __i, difference_type __n) > > > > > >constexpr? > > > > Fixed. I've added tests that all iterator ops are usable in constant > > expressions, which found a bug in operator+= (it didn't let you > > increment one past the end of the range). > > I found another bug in operator+= which is fixed and tested like so: > > --- a/libstdc++-v3/include/std/text_encoding > +++ b/libstdc++-v3/include/std/text_encoding > @@ -584,7 +584,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > *this == _Iterator{}; > } > } > - __glibcxx_assert(_M_rep != nullptr); > + if (__n != 0) > + __glibcxx_assert(_M_rep != nullptr); > return *this; > } > > --- a/libstdc++-v3/testsuite/std/text_encoding/requirements.cc > +++ b/libstdc++-v3/testsuite/std/text_encoding/requirements.cc > @@ -67,6 +67,11 @@ test_constexpr_iterator() > VERIFY( *(iter + 1) == iter[1] ); > VERIFY( (1 + iter - 1) == begin ); > VERIFY( (-1 + (iter - -2) + -1) == begin ); > + > + std::ranges::iterator_t<std::text_encoding::aliases_view> singular; > + VERIFY( (singular + 0) == singular ); > + VERIFY( (singular - 0) == singular ); > + > return true; > } > static_assert( test_constexpr_iterator() );
I'll also change this, after a suggestion from one of the paper authors (Corentin): --- a/libstdc++-v3/src/c++26/text_encoding.cc +++ b/libstdc++-v3/src/c++26/text_encoding.cc @@ -38,7 +38,7 @@ text_encoding __locale_encoding(const char* name) { text_encoding enc; - if (locale_t loc = ::newlocale(LC_ALL_MASK, name, (locale_t)0)) + if (locale_t loc = ::newlocale(LC_CTYPE_MASK, name, (locale_t)0)) { if (const char* codeset = ::nl_langinfo_l(CODESET, loc)) { @@ -64,7 +64,7 @@ bool std::text_encoding::_M_is_environment() const { bool matched = false; - if (locale_t loc = ::newlocale(LC_ALL_MASK, "", (locale_t)0)) + if (locale_t loc = ::newlocale(LC_CTYPE_MASK, "", (locale_t)0)) { if (const char* codeset = ::nl_langinfo_l(CODESET, loc)) {