diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2016-10-10 16:34:28 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2016-10-10 16:34:28 +0100 |
commit | 9e023e3321886e0ba1ea7b25c7ef70e50c267963 (patch) | |
tree | 0ae19e10645befcea07ccd7b6638f0cdf12001ec | |
parent | 5f869266133f8ad66688c2ff7eaa6f7b0a0f21d0 (diff) | |
download | gcc-9e023e3321886e0ba1ea7b25c7ef70e50c267963.zip gcc-9e023e3321886e0ba1ea7b25c7ef70e50c267963.tar.gz gcc-9e023e3321886e0ba1ea7b25c7ef70e50c267963.tar.bz2 |
Implement constexpr std::addressof for C++17
* doc/xml/manual/intro.xml: Document DR 2296 status.
* doc/xml/manual/status_cxx2017.xml: Update status.
* include/bits/move.h (__addressof): Add _GLIBCXX_CONSTEXPR and
call __builtin_addressof.
(addressof): Add _GLIBCXX17_CONSTEXPR.
* testsuite/20_util/addressof/requirements/constexpr.cc: New test.
* testsuite/20_util/forward/c_neg.cc: Adjust dg-error lineno.
* testsuite/20_util/forward/f_neg.cc: Likewise.
From-SVN: r240929
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/doc/xml/manual/intro.xml | 7 | ||||
-rw-r--r-- | libstdc++-v3/doc/xml/manual/status_cxx2017.xml | 3 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/move.h | 14 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/addressof/requirements/constexpr.cc | 55 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/forward/c_neg.cc | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/forward/f_neg.cc | 2 |
7 files changed, 82 insertions, 10 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d1e2bc3..34b7d05 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ 2016-10-10 Jonathan Wakely <jwakely@redhat.com> + * doc/xml/manual/intro.xml: Document DR 2296 status. + * doc/xml/manual/status_cxx2017.xml: Update status. + * include/bits/move.h (__addressof): Add _GLIBCXX_CONSTEXPR and + call __builtin_addressof. + (addressof): Add _GLIBCXX17_CONSTEXPR. + * testsuite/20_util/addressof/requirements/constexpr.cc: New test. + * testsuite/20_util/forward/c_neg.cc: Adjust dg-error lineno. + * testsuite/20_util/forward/f_neg.cc: Likewise. + * include/bits/allocator.h (allocator<T>::is_always_equal): Define. * testsuite/20_util/allocator/requirements/typedefs.cc: Test for is_always_equal. diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 4747851..265ef67 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -961,6 +961,13 @@ requirements of the license of GCC. is included by <code><array></code>. </para></listitem></varlistentry> + <varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2296">2296</link>: + <emphasis><code>std::addressof</code> should be constexpr</emphasis> + </term> + <listitem><para>Use <code>__builtin_addressof</code> and add + <code>constexpr</code> to <code>addressof</code> for C++17 and later. + </para></listitem></varlistentry> + <varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2313">2313</link>: <emphasis><code>tuple_size</code> should always derive from <code>integral_constant<size_t, N></code></emphasis> </term> diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml index c03978e..c6b8440 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml @@ -253,14 +253,13 @@ Feature-testing recommendations for C++</link>. </row> <row> - <?dbhtml bgcolor="#C8B0B0" ?> <entry> <code>std::addressof</code> should be constexpr </entry> <entry> <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0304r0.html#2296"> LWG2296 </link> </entry> - <entry align="center"> No </entry> + <entry align="center"> 7 </entry> <entry><code> __cpp_lib_addressof_constexpr >= 201603 </code></entry> </row> diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h index 9deec42..a5002fc 100644 --- a/libstdc++-v3/include/bits/move.h +++ b/libstdc++-v3/include/bits/move.h @@ -43,12 +43,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @ingroup utilities */ template<typename _Tp> - inline _Tp* + inline _GLIBCXX_CONSTEXPR _Tp* __addressof(_Tp& __r) _GLIBCXX_NOEXCEPT - { - return reinterpret_cast<_Tp*> - (&const_cast<char&>(reinterpret_cast<const volatile char&>(__r))); - } + { return __builtin_addressof(__r); } _GLIBCXX_END_NAMESPACE_VERSION } // namespace @@ -123,6 +120,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // declval, from type_traits. +#if __cplusplus > 201402L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2296. std::addressof should be constexpr +# define __cpp_lib_addressof_constexpr 201603 +#endif /** * @brief Returns the actual address of the object or function * referenced by r, even in the presence of an overloaded @@ -131,7 +133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return The actual address. */ template<typename _Tp> - inline _Tp* + inline _GLIBCXX17_CONSTEXPR _Tp* addressof(_Tp& __r) noexcept { return std::__addressof(__r); } diff --git a/libstdc++-v3/testsuite/20_util/addressof/requirements/constexpr.cc b/libstdc++-v3/testsuite/20_util/addressof/requirements/constexpr.cc new file mode 100644 index 0000000..998d087 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/addressof/requirements/constexpr.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++1z" } +// { dg-do compile { target c++1z } } + +#include <utility> + +// LWG 2296 std::addressof should be constexpr + +#ifndef __cpp_lib_addressof_constexpr +# error "Feature-test macro for constexpr addressof missing" +#elif __cpp_lib_addressof_constexpr != 201603 +# error "Feature-test macro for constexpr addressof has wrong value" +#endif + +int i; +constexpr int* pi = std::addressof(i); +static_assert( pi == &i, "&i" ); + +struct X { + void operator&(); + constexpr X* addr() { return this; } + constexpr const X* addr() const { return this; } +}; +X x; +constexpr X* px = std::addressof(x); +static_assert( px == x.addr(), "x.addr()" ); +const X cx; +constexpr const X* pcx = std::addressof(cx); +static_assert( pcx == cx.addr(), "cx.addr()" ); + +void +test01() +{ + static int i2; + static_assert( std::addressof(i2) == &i2, "&i2" ); + + static X x2; + static_assert( std::addressof(x2) == x2.addr(), "x2.addr()" ); +} diff --git a/libstdc++-v3/testsuite/20_util/forward/c_neg.cc b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc index 0b23625..784e23c 100644 --- a/libstdc++-v3/testsuite/20_util/forward/c_neg.cc +++ b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc @@ -17,7 +17,7 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -// { dg-error "static assertion failed" "" { target *-*-* } 89 } +// { dg-error "static assertion failed" "" { target *-*-* } 86 } #include <list> diff --git a/libstdc++-v3/testsuite/20_util/forward/f_neg.cc b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc index 9796ef4..3f4c175 100644 --- a/libstdc++-v3/testsuite/20_util/forward/f_neg.cc +++ b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc @@ -17,7 +17,7 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -// { dg-error "static assertion failed" "" { target *-*-* } 89 } +// { dg-error "static assertion failed" "" { target *-*-* } 86 } #include <utility> |