public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Add check for LWG 3741 problem case
@ 2022-08-24 13:05 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2022-08-24 13:05 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested powerpc64le-linux, pushed to trunk.

-- >8 --

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.
---
 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<seconds>(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<int, std::ratio<1000, 1000>>;
+static_assert( std::chrono::abs(D1000(-2)) == D1000(2) );
+static_assert( std::is_same_v<decltype(std::chrono::abs(D1000(-2))), D1000> );
-- 
2.37.2


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

only message in thread, other threads:[~2022-08-24 13:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-24 13:05 [committed] libstdc++: Add check for LWG 3741 problem case 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).