* Should reinterpret_cast be constexpr? @ 2020-12-28 19:51 Josh Marshall 2020-12-28 20:33 ` Jonathan Wakely 0 siblings, 1 reply; 6+ messages in thread From: Josh Marshall @ 2020-12-28 19:51 UTC (permalink / raw) To: libstdc++ Hello all, From the test error `libstdc++-v3/include/bits/stl_vector.h:1837: error: 'reinterpret_cast' is not a constant expression` and the documentation at https://en.cppreference.com/w/cpp/language/reinterpret_cast , is `reinterpret_cast()` not constexpr in error? ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Should reinterpret_cast be constexpr? 2020-12-28 19:51 Should reinterpret_cast be constexpr? Josh Marshall @ 2020-12-28 20:33 ` Jonathan Wakely 2020-12-28 20:47 ` Jonathan Wakely 0 siblings, 1 reply; 6+ messages in thread From: Jonathan Wakely @ 2020-12-28 20:33 UTC (permalink / raw) To: Josh Marshall; +Cc: libstdc++ On Mon, 28 Dec 2020 at 19:51, Josh Marshall via Libstdc++ <libstdc++@gcc.gnu.org> wrote: > > Hello all, > > From the test error `libstdc++-v3/include/bits/stl_vector.h:1837: error: > 'reinterpret_cast' is not a constant expression` and the documentation at > https://en.cppreference.com/w/cpp/language/reinterpret_cast , is > `reinterpret_cast()` not constexpr in error? No, it's not an error. reinterpret_cast is not allowed in constant expressions. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Should reinterpret_cast be constexpr? 2020-12-28 20:33 ` Jonathan Wakely @ 2020-12-28 20:47 ` Jonathan Wakely 2020-12-28 20:49 ` Josh Marshall 0 siblings, 1 reply; 6+ messages in thread From: Jonathan Wakely @ 2020-12-28 20:47 UTC (permalink / raw) To: Josh Marshall; +Cc: libstdc++ On Mon, 28 Dec 2020 at 20:33, Jonathan Wakely <jwakely.gcc@gmail.com> wrote: > > On Mon, 28 Dec 2020 at 19:51, Josh Marshall via Libstdc++ > <libstdc++@gcc.gnu.org> wrote: > > > > Hello all, > > > > From the test error `libstdc++-v3/include/bits/stl_vector.h:1837: error: > > 'reinterpret_cast' is not a constant expression` and the documentation at > > https://en.cppreference.com/w/cpp/language/reinterpret_cast , is > > `reinterpret_cast()` not constexpr in error? > > No, it's not an error. reinterpret_cast is not allowed in constant expressions. This patch replaces the use of reinterpret_cast with an alternative using C++20 features: diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index 27e63388feb..93b2ccc02e3 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -516,9 +516,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { #if __cplusplus < 201103L value_type __x_copy = __x; -#else +#elif ! __cpp_lib_make_obj_using_allocator _Temporary_value __tmp(this, __x); value_type& __x_copy = __tmp._M_val(); +#else + value_type __x_copy = std::make_from_tuple<value_type>( + std::uses_allocator_construction_args<value_type>( + _M_get_Tp_allocator(), __x)); #endif const size_type __elems_after = end() - __position; pointer __old_finish(this->_M_impl._M_finish); ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Should reinterpret_cast be constexpr? 2020-12-28 20:47 ` Jonathan Wakely @ 2020-12-28 20:49 ` Josh Marshall 2020-12-28 21:24 ` Jonathan Wakely 0 siblings, 1 reply; 6+ messages in thread From: Josh Marshall @ 2020-12-28 20:49 UTC (permalink / raw) To: Jonathan Wakely; +Cc: libstdc++ Is this in master? If so, I'll just merge it in. On Mon, Dec 28, 2020 at 3:47 PM Jonathan Wakely <jwakely.gcc@gmail.com> wrote: > On Mon, 28 Dec 2020 at 20:33, Jonathan Wakely <jwakely.gcc@gmail.com> > wrote: > > > > On Mon, 28 Dec 2020 at 19:51, Josh Marshall via Libstdc++ > > <libstdc++@gcc.gnu.org> wrote: > > > > > > Hello all, > > > > > > From the test error `libstdc++-v3/include/bits/stl_vector.h:1837: > error: > > > 'reinterpret_cast' is not a constant expression` and the documentation > at > > > https://en.cppreference.com/w/cpp/language/reinterpret_cast , is > > > `reinterpret_cast()` not constexpr in error? > > > > No, it's not an error. reinterpret_cast is not allowed in constant > expressions. > > This patch replaces the use of reinterpret_cast with an alternative > using C++20 features: > > diff --git a/libstdc++-v3/include/bits/vector.tcc > b/libstdc++-v3/include/bits/vector.tcc > index 27e63388feb..93b2ccc02e3 100644 > --- a/libstdc++-v3/include/bits/vector.tcc > +++ b/libstdc++-v3/include/bits/vector.tcc > @@ -516,9 +516,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER > { > #if __cplusplus < 201103L > value_type __x_copy = __x; > -#else > +#elif ! __cpp_lib_make_obj_using_allocator > _Temporary_value __tmp(this, __x); > value_type& __x_copy = __tmp._M_val(); > +#else > + value_type __x_copy = std::make_from_tuple<value_type>( > + std::uses_allocator_construction_args<value_type>( > + _M_get_Tp_allocator(), __x)); > #endif > const size_type __elems_after = end() - __position; > pointer __old_finish(this->_M_impl._M_finish); > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Should reinterpret_cast be constexpr? 2020-12-28 20:49 ` Josh Marshall @ 2020-12-28 21:24 ` Jonathan Wakely [not found] ` <CAFkJGRem_HFTtj93pyWVpvMtjSDLBU8u9nUVXshOTovsEjDaHw@mail.gmail.com> 0 siblings, 1 reply; 6+ messages in thread From: Jonathan Wakely @ 2020-12-28 21:24 UTC (permalink / raw) To: Josh Marshall; +Cc: libstdc++ On Mon, 28 Dec 2020 at 20:50, Josh Marshall <joshua.r.marshall.1991@gmail.com> wrote: > > Is this in master? If so, I'll just merge it in. No, I just made a local change and haven't even committed it locally. > > On Mon, Dec 28, 2020 at 3:47 PM Jonathan Wakely <jwakely.gcc@gmail.com> wrote: >> >> On Mon, 28 Dec 2020 at 20:33, Jonathan Wakely <jwakely.gcc@gmail.com> wrote: >> > >> > On Mon, 28 Dec 2020 at 19:51, Josh Marshall via Libstdc++ >> > <libstdc++@gcc.gnu.org> wrote: >> > > >> > > Hello all, >> > > >> > > From the test error `libstdc++-v3/include/bits/stl_vector.h:1837: error: >> > > 'reinterpret_cast' is not a constant expression` and the documentation at >> > > https://en.cppreference.com/w/cpp/language/reinterpret_cast , is >> > > `reinterpret_cast()` not constexpr in error? >> > >> > No, it's not an error. reinterpret_cast is not allowed in constant expressions. >> >> This patch replaces the use of reinterpret_cast with an alternative >> using C++20 features: >> >> diff --git a/libstdc++-v3/include/bits/vector.tcc >> b/libstdc++-v3/include/bits/vector.tcc >> index 27e63388feb..93b2ccc02e3 100644 >> --- a/libstdc++-v3/include/bits/vector.tcc >> +++ b/libstdc++-v3/include/bits/vector.tcc >> @@ -516,9 +516,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER >> { >> #if __cplusplus < 201103L >> value_type __x_copy = __x; >> -#else >> +#elif ! __cpp_lib_make_obj_using_allocator >> _Temporary_value __tmp(this, __x); >> value_type& __x_copy = __tmp._M_val(); >> +#else >> + value_type __x_copy = std::make_from_tuple<value_type>( >> + std::uses_allocator_construction_args<value_type>( >> + _M_get_Tp_allocator(), __x)); >> #endif >> const size_type __elems_after = end() - __position; >> pointer __old_finish(this->_M_impl._M_finish); ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CAFkJGRem_HFTtj93pyWVpvMtjSDLBU8u9nUVXshOTovsEjDaHw@mail.gmail.com>]
* Re: Should reinterpret_cast be constexpr? [not found] ` <CAFkJGRem_HFTtj93pyWVpvMtjSDLBU8u9nUVXshOTovsEjDaHw@mail.gmail.com> @ 2020-12-29 1:19 ` Josh Marshall 0 siblings, 0 replies; 6+ messages in thread From: Josh Marshall @ 2020-12-29 1:19 UTC (permalink / raw) To: Jonathan Wakely, libstdc++ I think it is time for a check in. I have two tests failing, one related to the code your snippet tries to fix and another which looks like a bug in swapping elements. https://gitlab.com/anadon/gcc The lines of interest are libstdc++-v3/testsuite/23_containers/vector/constexpr/swap_element.cc:67 (bug) libstdc++-v3/testsuite/23_containers/vector/constexpr/swap_element.cc:130 (bug) libstdc++-v3/testsuite/23_containers/vector/constexpr/function_insert.cc:35 (needs implementation) Those are what I see as the current problems. Now might also be the time to start examining the rest of the work. There's no way I kept to coding standards when I'm this new. On Mon, Dec 28, 2020 at 4:53 PM Josh Marshall < joshua.r.marshall.1991@gmail.com> wrote: > OK. Thanks for the freebie :) > > On Mon, Dec 28, 2020 at 4:25 PM Jonathan Wakely <jwakely.gcc@gmail.com> > wrote: > >> On Mon, 28 Dec 2020 at 20:50, Josh Marshall >> <joshua.r.marshall.1991@gmail.com> wrote: >> > >> > Is this in master? If so, I'll just merge it in. >> >> No, I just made a local change and haven't even committed it locally. >> >> >> > >> > On Mon, Dec 28, 2020 at 3:47 PM Jonathan Wakely <jwakely.gcc@gmail.com> >> wrote: >> >> >> >> On Mon, 28 Dec 2020 at 20:33, Jonathan Wakely <jwakely.gcc@gmail.com> >> wrote: >> >> > >> >> > On Mon, 28 Dec 2020 at 19:51, Josh Marshall via Libstdc++ >> >> > <libstdc++@gcc.gnu.org> wrote: >> >> > > >> >> > > Hello all, >> >> > > >> >> > > From the test error `libstdc++-v3/include/bits/stl_vector.h:1837: >> error: >> >> > > 'reinterpret_cast' is not a constant expression` and the >> documentation at >> >> > > https://en.cppreference.com/w/cpp/language/reinterpret_cast , is >> >> > > `reinterpret_cast()` not constexpr in error? >> >> > >> >> > No, it's not an error. reinterpret_cast is not allowed in constant >> expressions. >> >> >> >> This patch replaces the use of reinterpret_cast with an alternative >> >> using C++20 features: >> >> >> >> diff --git a/libstdc++-v3/include/bits/vector.tcc >> >> b/libstdc++-v3/include/bits/vector.tcc >> >> index 27e63388feb..93b2ccc02e3 100644 >> >> --- a/libstdc++-v3/include/bits/vector.tcc >> >> +++ b/libstdc++-v3/include/bits/vector.tcc >> >> @@ -516,9 +516,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER >> >> { >> >> #if __cplusplus < 201103L >> >> value_type __x_copy = __x; >> >> -#else >> >> +#elif ! __cpp_lib_make_obj_using_allocator >> >> _Temporary_value __tmp(this, __x); >> >> value_type& __x_copy = __tmp._M_val(); >> >> +#else >> >> + value_type __x_copy = std::make_from_tuple<value_type>( >> >> + std::uses_allocator_construction_args<value_type>( >> >> + _M_get_Tp_allocator(), __x)); >> >> #endif >> >> const size_type __elems_after = end() - __position; >> >> pointer __old_finish(this->_M_impl._M_finish); >> > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-12-29 1:19 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-12-28 19:51 Should reinterpret_cast be constexpr? Josh Marshall 2020-12-28 20:33 ` Jonathan Wakely 2020-12-28 20:47 ` Jonathan Wakely 2020-12-28 20:49 ` Josh Marshall 2020-12-28 21:24 ` Jonathan Wakely [not found] ` <CAFkJGRem_HFTtj93pyWVpvMtjSDLBU8u9nUVXshOTovsEjDaHw@mail.gmail.com> 2020-12-29 1:19 ` Josh Marshall
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).