public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4582] libstdc++: Add missing test for std::optional::transform(F&&)
@ 2021-10-20 19:20 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-10-20 19:20 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:4ba4b053151a20262d4b61eb4501aa1c48337abb

commit r12-4582-g4ba4b053151a20262d4b61eb4501aa1c48337abb
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Oct 20 20:12:28 2021 +0100

    libstdc++: Add missing test for std::optional::transform(F&&)
    
    The test_copy_elision() function was supposed to ensure that the result
    is constructed directly in the std::optional, without early temporary
    materialization. But I forgot to write the test.
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/20_util/optional/monadic/transform.cc: Check that
            an rvalue result is not materialized too soon.

Diff:
---
 .../testsuite/20_util/optional/monadic/transform.cc     | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc b/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc
index d01ccb2e0f2..13977b8ba8d 100644
--- a/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc
+++ b/libstdc++-v3/testsuite/20_util/optional/monadic/transform.cc
@@ -110,6 +110,23 @@ static_assert( test_forwarding() );
 constexpr bool
 test_copy_elision()
 {
+  struct immovable
+  {
+    constexpr immovable(int p) : power_level(p) { }
+    immovable(immovable&&) = delete;
+
+    int power_level;
+  };
+
+  struct Force
+  {
+    constexpr immovable operator()(int i) const { return {i+1}; }
+  };
+
+  std::optional<int> irresistible(9000);
+  std::optional<immovable> object = irresistible.transform(Force{});
+  VERIFY( object->power_level > 9000 );
+
   return true;
 }


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

only message in thread, other threads:[~2021-10-20 19:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-20 19:20 [gcc r12-4582] libstdc++: Add missing test for std::optional::transform(F&&) 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).