From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 3711E385C32E; Wed, 24 Aug 2022 13:04:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3711E385C32E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661346271; bh=Ol7E1D8V0KR7fVK9kavX2OPW9MXvN4J/b2GbhUus90o=; h=From:To:Subject:Date:From; b=XwzXr2s2p4bn9/55V3VRYo3BarT9Up0kWqieumxo3gMAaCqIfAlbw6kgMwc/OMvE2 A4MMrd50wtoWEorSVU3t+hBPm37SGBb1YPeiVC5ZT7tlfzdBKWs4Ocybzd42lj5fYk tH8r4D9YnJiWJhlYoM4cLnB0mkaH2fyWKNC04szU= 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 r13-2172] libstdc++: Add check for LWG 3741 problem case X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 4a907b15b551becd3145061a8906089267db5a04 X-Git-Newrev: f0f04e1dffea609cb74ac0b488385401ed7e15a3 Message-Id: <20220824130431.3711E385C32E@sourceware.org> Date: Wed, 24 Aug 2022 13:04:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f0f04e1dffea609cb74ac0b488385401ed7e15a3 commit r13-2172-gf0f04e1dffea609cb74ac0b488385401ed7e15a3 Author: Jonathan Wakely Date: Wed Aug 24 00:10:59 2022 +0100 libstdc++: Add check for LWG 3741 problem case This LWG issue was closed as NAD, as it was just a bug in an implementation, not a defect in the standard. Libstdc++ never had that bug and always worked for the problem case. Add a test to ensure we don't regress. The problem occurs when abs is implemented using a ternary expression: return d >= d.zero() ? d : -d; If decltype(-d) is not the same as decltype(d) then this is ambiguous, because each type can be converted to the other, so there is no common type. libstdc++-v3/ChangeLog: * testsuite/20_util/duration_cast/rounding.cc: Check abs with non-reduced duration. Diff: --- libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc b/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc index af6e72d9e2e..c5179b6eb6e 100644 --- a/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc +++ b/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc @@ -58,3 +58,8 @@ static_assert( std::chrono::round(2501ms) == 3s ); static_assert( std::chrono::abs(100ms) == 100ms ); static_assert( std::chrono::abs(-100ms) == 100ms ); + +// LWG 3741. std::chrono::abs(duration) is ill-formed with non-reduced periods +using D1000 = std::chrono::duration>; +static_assert( std::chrono::abs(D1000(-2)) == D1000(2) ); +static_assert( std::is_same_v );