public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Constexpr in std::pointer_traits (P1006R1)
@ 2019-03-06 12:13 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2019-03-06 12:13 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 207 bytes --]

	* 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.

Tested powerpc64le-linux, committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2292 bytes --]

commit 8125740feaa7aa66589d0922992b9bf1065e1699
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Mar 6 10:45:02 2019 +0000

    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.

diff --git a/libstdc++-v3/include/bits/ptr_traits.h b/libstdc++-v3/include/bits/ptr_traits.h
index 76355863852..c90a35080f1 100644
--- a/libstdc++-v3/include/bits/ptr_traits.h
+++ b/libstdc++-v3/include/bits/ptr_traits.h
@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  @param  __r  A reference to an object of type @c element_type
        *  @return @c addressof(__r)
       */
-      static pointer
+      static _GLIBCXX20_CONSTEXPR pointer
       pointer_to(__make_not_void<element_type>& __r) noexcept
       { return std::addressof(__r); }
     };
diff --git a/libstdc++-v3/testsuite/20_util/pointer_traits/pointer_to_constexpr.cc b/libstdc++-v3/testsuite/20_util/pointer_traits/pointer_to_constexpr.cc
new file mode 100644
index 00000000000..ed4f2157adc
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/pointer_traits/pointer_to_constexpr.cc
@@ -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 );

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-03-06 11:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-06 12:13 [PATCH] Constexpr in std::pointer_traits (P1006R1) Jonathan Wakely

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).