From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 78A3E3858038; Fri, 26 Nov 2021 12:39:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78A3E3858038 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-5539] libstdc++: Move std::to_address tests to more appropriate place X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: a70faf6e4df7481c2c9a08a06657c20beb3043de X-Git-Newrev: 0178b73a02021551f83e3e52c4819c4096513301 Message-Id: <20211126123907.78A3E3858038@sourceware.org> Date: Fri, 26 Nov 2021 12:39:07 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2021 12:39:07 -0000 https://gcc.gnu.org/g:0178b73a02021551f83e3e52c4819c4096513301 commit r12-5539-g0178b73a02021551f83e3e52c4819c4096513301 Author: Jonathan Wakely Date: Fri Nov 26 11:03:06 2021 +0000 libstdc++: Move std::to_address tests to more appropriate place 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. Diff: --- .../testsuite/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, clever_ptr>::value, "" ); static_assert( is_same, std::ptrdiff_t>::value, "" ); static_assert( is_same, clever_ptr>::value, "" ); static_assert( is_same, clever_ptr>::value, "" ); - -#if __cplusplus >= 202002L -static_assert( std::to_address(clever_ptr{}) == &clever_ptr::obj, "" ); - -int the_int; - -template<> -struct std::pointer_traits> -{ - using element_type = int; - using difference_type = std::ptrdiff_t; - using pointer = clever_ptr; - - static constexpr int* to_address(pointer p) { return &the_int; } -}; - -// Should use pointer_traits>::to_address -static_assert( std::to_address(clever_ptr{}) == &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 @@ -10,3 +10,28 @@ template struct nttp_ptr // This gives an error in C++20, which the LWG 3545 resolution should fix: auto x = std::to_address( nttp_ptr() ); + +template +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{}) == &clever_ptr::obj ); + +int the_int; + +template<> +struct std::pointer_traits> +{ + using element_type = int; + using difference_type = std::ptrdiff_t; + using pointer = clever_ptr; + + static constexpr int* to_address(pointer p) { return &the_int; } +}; + +// Uses pointer_traits>::to_address +static_assert( std::to_address(clever_ptr{}) == &the_int );