public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc/devel/c++-modules] libstdc++: tuple_element_t is also wrong for const subrange (LWG 3398)
Date: Mon, 24 Feb 2020 16:29:00 -0000	[thread overview]
Message-ID: <20200224162910.103179.qmail@sourceware.org> (raw)

https://gcc.gnu.org/g:fa89adaa979093936d8f148ef5496db05ad308e5

commit fa89adaa979093936d8f148ef5496db05ad308e5
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Feb 19 11:37:54 2020 +0000

    libstdc++: tuple_element_t is also wrong for const subrange (LWG 3398)
    
    	* include/std/ranges (tuple_element<0, const subrange<I, S, K>>)
    	(tuple_element<1, const subrange<I, S, K>>): Add partial
    	specializations (LWG 3398).
    	* testsuite/std/ranges/subrange/tuple_like.cc: New test.

Diff:
---
 libstdc++-v3/ChangeLog                             |  5 +++
 libstdc++-v3/include/std/ranges                    |  9 +++-
 .../testsuite/std/ranges/subrange/tuple_like.cc    | 52 ++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index a8fcd7c..f69507d 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,10 @@
 2020-02-19  Jonathan Wakely  <jwakely@redhat.com>
 
+	* include/std/ranges (tuple_element<0, const subrange<I, S, K>>)
+	(tuple_element<1, const subrange<I, S, K>>): Add partial
+	specializations (LWG 3398).
+	* testsuite/std/ranges/subrange/tuple_like.cc: New test.
+
 	* include/bits/ranges_algo.h (__find_fn, __find_first_of_fn)
 	(__adjacent_find_fn, __remove_if_fn, __remove_copy_if_fn)
 	(__unique_fn, __unique_copy_fn): Remove redundant conversions to bool.
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index e0eb847..4e50206 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -3193,7 +3193,6 @@ namespace views
 	typename tuple_size<_Tp>::type;
 	requires _Nm < tuple_size_v<_Tp>;
 	typename tuple_element_t<_Nm, _Tp>;
-	// XXX: we applied P3323 here
 	{ std::get<_Nm>(__t) }
 	  -> convertible_to<const tuple_element_t<_Nm, _Tp>&>;
       };
@@ -3451,6 +3450,14 @@ namespace views
     struct tuple_element<1, ranges::subrange<_Iter, _Sent, _Kind>>
     { using type = _Sent; };
 
+  template<typename _Iter, typename _Sent, ranges::subrange_kind _Kind>
+    struct tuple_element<0, const ranges::subrange<_Iter, _Sent, _Kind>>
+    { using type = _Iter; };
+
+  template<typename _Iter, typename _Sent, ranges::subrange_kind _Kind>
+    struct tuple_element<1, const ranges::subrange<_Iter, _Sent, _Kind>>
+    { using type = _Sent; };
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 #endif // library concepts
diff --git a/libstdc++-v3/testsuite/std/ranges/subrange/tuple_like.cc b/libstdc++-v3/testsuite/std/ranges/subrange/tuple_like.cc
new file mode 100644
index 0000000..a3020d2
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/ranges/subrange/tuple_like.cc
@@ -0,0 +1,52 @@
+// Copyright (C) 2020 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 <ranges>
+
+using S1 = std::ranges::subrange<int*>;
+using S2 = std::ranges::subrange<long*, void*>;
+
+static_assert( std::tuple_size_v<S1> == 2 );
+static_assert( std::tuple_size_v<S2> == 2 );
+
+static_assert( std::same_as<std::tuple_element_t<0, S1>, int*> );
+static_assert( std::same_as<std::tuple_element_t<1, S1>, int*> );
+// LWG 3398
+static_assert( std::same_as<std::tuple_element_t<0, const S1>, int*> );
+static_assert( std::same_as<std::tuple_element_t<1, const S1>, int*> );
+
+static_assert( std::same_as<std::tuple_element_t<0, S2>, long*> );
+static_assert( std::same_as<std::tuple_element_t<1, S2>, void*> );
+// LWG 3398
+static_assert( std::same_as<std::tuple_element_t<0, const S2>, long*> );
+static_assert( std::same_as<std::tuple_element_t<1, const S2>, void*> );
+
+S1 s1;
+static_assert( std::same_as<decltype(std::get<0>(s1)), int*> );
+static_assert( std::same_as<decltype(std::get<1>(s1)), int*> );
+const S1 c1;
+static_assert( std::same_as<decltype(std::get<0>(c1)), int*> );
+static_assert( std::same_as<decltype(std::get<1>(c1)), int*> );
+S2 s2;
+static_assert( std::same_as<decltype(std::get<0>(s2)), long*> );
+static_assert( std::same_as<decltype(std::get<1>(s2)), void*> );
+const S2 c2;
+static_assert( std::same_as<decltype(std::get<0>(c2)), long*> );
+static_assert( std::same_as<decltype(std::get<1>(c2)), void*> );


                 reply	other threads:[~2020-02-24 16:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200224162910.103179.qmail@sourceware.org \
    --to=nathan@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).