public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Fix up semiregular-box partial specialization [PR100475]
@ 2021-05-17 15:43 Patrick Palka
  2021-05-17 16:45 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2021-05-17 15:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Patrick Palka

This makes the in-place constructor of our partial specialization of
__box for already-semiregular types to use direct-non-list-initialization
(in accordance with the specification of the primary template), and
additionally makes its data() member function use std::__addressof.

Tested on x86_64-pc-linux-gnu, does this look OK for 10/11/trunk?

libstdc++-v3/ChangeLog:

	PR libstdc++/100475
	* include/std/ranges (__box::__box): Use non-list-initialization
	in member initializer list of in-place constructor of the
	partial specialization for semiregular types.
	(__box::operator->): Use std::__addressof.
	* testsuite/std/ranges/adaptors/detail/semiregular_box.cc
	(test02): New test.
	* testsuite/std/ranges/single_view.cc (test04): New test.
---
 libstdc++-v3/include/std/ranges                |  6 +++---
 .../ranges/adaptors/detail/semiregular_box.cc  | 18 ++++++++++++++++++
 .../testsuite/std/ranges/single_view.cc        | 16 ++++++++++++++++
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 0f69d4f0839..1707aeaebcd 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -163,7 +163,7 @@ namespace ranges
 	  constexpr explicit
 	  __box(in_place_t, _Args&&... __args)
 	  noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
-	  : _M_value{std::forward<_Args>(__args)...}
+	  : _M_value(std::forward<_Args>(__args)...)
 	  { }
 
 	constexpr bool
@@ -180,11 +180,11 @@ namespace ranges
 
 	constexpr _Tp*
 	operator->() noexcept
-	{ return &_M_value; }
+	{ return std::__addressof(_M_value); }
 
 	constexpr const _Tp*
 	operator->() const noexcept
-	{ return &_M_value; }
+	{ return std::__addressof(_M_value); }
       };
   } // namespace __detail
 
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc
index 65931dea51a..ed694e04fd1 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc
@@ -81,3 +81,21 @@ test01()
   return true;
 }
 static_assert(test01());
+
+template<bool make_semiregular>
+  struct A {
+    A() requires make_semiregular;
+    A(int, int);
+    A(std::initializer_list<int>) = delete;
+  };
+
+void
+test02()
+{
+  // PR libstdc++/100475
+  static_assert(std::semiregular<A<true>>);
+  __box<A<true>> x2(std::in_place, 0, 0);
+
+  static_assert(!std::semiregular<A<false>>);
+  __box<A<false>> x1(std::in_place, 0, 0);
+}
diff --git a/libstdc++-v3/testsuite/std/ranges/single_view.cc b/libstdc++-v3/testsuite/std/ranges/single_view.cc
index 97bc39bb636..f530cc07565 100644
--- a/libstdc++-v3/testsuite/std/ranges/single_view.cc
+++ b/libstdc++-v3/testsuite/std/ranges/single_view.cc
@@ -58,9 +58,25 @@ test03()
   VERIFY(*std::ranges::begin(s3) == 'a');
 }
 
+void
+test04()
+{
+  // PR libstdc++/100475
+  struct A {
+    A() = default;
+    A(int, int) { }
+    A(std::initializer_list<int>) = delete;
+    void operator&() const = delete;
+  };
+  std::ranges::single_view<A> s(std::in_place, 0, 0);
+  s.data();
+  std::as_const(s).data();
+}
+
 int main()
 {
   test01();
   test02();
   test03();
+  test04();
 }
-- 
2.31.1.621.g97eea85a0a


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libstdc++: Fix up semiregular-box partial specialization [PR100475]
  2021-05-17 15:43 [PATCH] libstdc++: Fix up semiregular-box partial specialization [PR100475] Patrick Palka
@ 2021-05-17 16:45 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-05-17 16:45 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, libstdc++

On 17/05/21 11:43 -0400, Patrick Palka via Libstdc++ wrote:
>This makes the in-place constructor of our partial specialization of
>__box for already-semiregular types to use direct-non-list-initialization
>(in accordance with the specification of the primary template), and
>additionally makes its data() member function use std::__addressof.
>
>Tested on x86_64-pc-linux-gnu, does this look OK for 10/11/trunk?

Yes for all, thanks.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-17 16:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 15:43 [PATCH] libstdc++: Fix up semiregular-box partial specialization [PR100475] Patrick Palka
2021-05-17 16:45 ` 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).