public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2172] libstdc++: Add check for LWG 3741 problem case Date: Wed, 24 Aug 2022 13:04:31 +0000 (GMT) [thread overview] Message-ID: <20220824130431.3711E385C32E@sourceware.org> (raw) https://gcc.gnu.org/g:f0f04e1dffea609cb74ac0b488385401ed7e15a3 commit r13-2172-gf0f04e1dffea609cb74ac0b488385401ed7e15a3 Author: Jonathan Wakely <jwakely@redhat.com> 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<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> );
reply other threads:[~2022-08-24 13:04 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220824130431.3711E385C32E@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).