From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 919413858409; Wed, 20 Oct 2021 19:20:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 919413858409 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-4582] libstdc++: Add missing test for std::optional::transform(F&&) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 154c6d430ee173904237de64d5aae11565201318 X-Git-Newrev: 4ba4b053151a20262d4b61eb4501aa1c48337abb Message-Id: <20211020192032.919413858409@sourceware.org> Date: Wed, 20 Oct 2021 19:20:32 +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: Wed, 20 Oct 2021 19:20:32 -0000 https://gcc.gnu.org/g:4ba4b053151a20262d4b61eb4501aa1c48337abb commit r12-4582-g4ba4b053151a20262d4b61eb4501aa1c48337abb Author: Jonathan Wakely 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 irresistible(9000); + std::optional object = irresistible.transform(Force{}); + VERIFY( object->power_level > 9000 ); + return true; }