Constexpr in std::pointer_traits (P1006R1)

* include/bits/ptr_traits.h [C++20] (pointer_traits<T*>::pointer_to):
	Add constexpr.
	* testsuite/20_util/pointer_traits/pointer_to_constexpr.cc: New test.

From-SVN: r269418
This commit is contained in:
Jonathan Wakely 2019-03-06 11:32:42 +00:00 committed by Jonathan Wakely
parent 9f54ba8f7d
commit d80f04d61e
3 changed files with 34 additions and 1 deletions

View File

@ -1,3 +1,9 @@
2019-03-06 Jonathan Wakely <jwakely@redhat.com>
* include/bits/ptr_traits.h [C++20] (pointer_traits<T*>::pointer_to):
Add constexpr.
* testsuite/20_util/pointer_traits/pointer_to_constexpr.cc: New test.
2019-03-05 Jonathan Wakely <jwakely@redhat.com> 2019-03-05 Jonathan Wakely <jwakely@redhat.com>
* include/c_compatibility/math.h [C++20] (lerp): Add using * include/c_compatibility/math.h [C++20] (lerp): Add using

View File

@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __r A reference to an object of type @c element_type * @param __r A reference to an object of type @c element_type
* @return @c addressof(__r) * @return @c addressof(__r)
*/ */
static pointer static _GLIBCXX20_CONSTEXPR pointer
pointer_to(__make_not_void<element_type>& __r) noexcept pointer_to(__make_not_void<element_type>& __r) noexcept
{ return std::addressof(__r); } { return std::addressof(__r); }
}; };

View File

@ -0,0 +1,27 @@
// Copyright (C) 2019 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++2a" }
// { dg-do compile { target c++2a } }
#include <memory>
int i = 0;
static_assert( std::pointer_traits<int*>::pointer_to(i) == &i );
struct X { } x;
static_assert( std::pointer_traits<X*>::pointer_to(x) == &x );