From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Move std::to_address tests to more appropriate place
Date: Fri, 26 Nov 2021 12:39:59 +0000 [thread overview]
Message-ID: <20211126123959.1662037-1-jwakely@redhat.com> (raw)
In-Reply-To: <20211125231243.1503399-1-jwakely@redhat.com>
Tested x86_64-linux, pushed to trunk.
Some of the checks in 20_util/pointer_traits/lwg3545.cc really belong in
20_util/to_address/lwg3545 instead.
This also fixes the ordering of the dg-options and dg-do directives.
libstdc++-v3/ChangeLog:
* testsuite/20_util/pointer_traits/lwg3545.cc: Move to_address
tests to ...
* testsuite/20_util/to_address/lwg3545.cc: ... here. Add -std
option before checking effective target.
---
.../20_util/pointer_traits/lwg3545.cc | 19 -------------
.../testsuite/20_util/to_address/lwg3545.cc | 27 ++++++++++++++++++-
2 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc b/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc
index 8325cb66d08..08c3ed01b75 100644
--- a/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc
+++ b/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc
@@ -99,22 +99,3 @@ static_assert( is_same<pointer<Ctraits>, clever_ptr<char>>::value, "" );
static_assert( is_same<difference_type<Ctraits>, std::ptrdiff_t>::value, "" );
static_assert( is_same<rebind<Ctraits>, clever_ptr<short>>::value, "" );
static_assert( is_same<pointer_to<Ctraits>, clever_ptr<char>>::value, "" );
-
-#if __cplusplus >= 202002L
-static_assert( std::to_address(clever_ptr<char>{}) == &clever_ptr<char>::obj, "" );
-
-int the_int;
-
-template<>
-struct std::pointer_traits<clever_ptr<int>>
-{
- using element_type = int;
- using difference_type = std::ptrdiff_t;
- using pointer = clever_ptr<int>;
-
- static constexpr int* to_address(pointer p) { return &the_int; }
-};
-
-// Should use pointer_traits<clever_ptr<int>>::to_address
-static_assert( std::to_address(clever_ptr<int>{}) == &the_int, "" );
-#endif
diff --git a/libstdc++-v3/testsuite/20_util/to_address/lwg3545.cc b/libstdc++-v3/testsuite/20_util/to_address/lwg3545.cc
index 4dc5fdcdde0..a80ac29b2c9 100644
--- a/libstdc++-v3/testsuite/20_util/to_address/lwg3545.cc
+++ b/libstdc++-v3/testsuite/20_util/to_address/lwg3545.cc
@@ -1,5 +1,5 @@
-// { dg-do compile { target c++20 } }
// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
#include <memory>
@@ -10,3 +10,28 @@ template<typename T, bool> struct nttp_ptr
// This gives an error in C++20, which the LWG 3545 resolution should fix:
auto x = std::to_address( nttp_ptr<int, true>() );
+
+template<typename T>
+struct clever_ptr
+{
+ static T obj;
+ constexpr T* operator->() const { return &obj; }
+};
+
+// pointer_traits specialization is valid, but to_address uses operator->
+static_assert( std::to_address(clever_ptr<char>{}) == &clever_ptr<char>::obj );
+
+int the_int;
+
+template<>
+struct std::pointer_traits<clever_ptr<int>>
+{
+ using element_type = int;
+ using difference_type = std::ptrdiff_t;
+ using pointer = clever_ptr<int>;
+
+ static constexpr int* to_address(pointer p) { return &the_int; }
+};
+
+// Uses pointer_traits<clever_ptr<int>>::to_address
+static_assert( std::to_address(clever_ptr<int>{}) == &the_int );
--
2.31.1
prev parent reply other threads:[~2021-11-26 12:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-25 23:12 [committed] libstdc++: Make std::pointer_traits SFINAE-friendly [PR96416] Jonathan Wakely
2021-11-26 12:39 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211126123959.1662037-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).