This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] PR libstdc++/81468 constrain std::chrono::time_point constructor
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Tim Song <t dot canens dot cpp at gmail dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 18 Sep 2017 21:00:38 +0100
- Subject: Re: [PATCH] PR libstdc++/81468 constrain std::chrono::time_point constructor
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jwakely at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 255DB285B5
- References: <20170913140903.GA8606@redhat.com> <20170913145546.GY4582@redhat.com> <CAPQZVxvC4RvP=hP08QMdrZ4zLzwU2Auz_kvRs3mfNEamo2J-gg@mail.gmail.com>
On 13/09/17 21:30 -0400, Tim Song wrote:
On Wed, Sep 13, 2017 at 10:55 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
+// DR 1177
+static_assert(is_constructible<duration<float>, duration<double>>{},
+ "can convert duration with one floating point rep to another");
+static_assert(is_constructible<duration<float>, duration<int>>{},
+ "can convert duration with integral rep to one with floating point rep");
+static_assert(!is_constructible<duration<int>, duration<float>>{},
+ "cannot convert duration with floating point rep to one with integral rep");
+static_assert(is_constructible<duration<int>, duration<long>>{},
+ "can convert duration with one integral rep to another");
+
+static_assert(!is_constructible<duration<int>, duration<int, ratio<2,3>>>{},
+ "cannot convert duration to one with different period");
+static_assert(is_constructible<duration<float>, duration<int, ratio<2,3>>>{},
+ "unless it has a floating-point representation");
"it" is a little ambiguous here unless you read the next message's
mention of "the original"...
+static_assert(is_constructible<duration<float>, duration<int, ratio<1,3>>>{},
+ "or a period that is an integral multiple of the original");
This is backwards: duration<Inty, P1> is convertible to duration<Inty,
P2> iff P1 is an integral multiple of P2, i.e., if the original's
period is an integral multiple of "its" period.
The static assert only passed because duration<float> was used as the
destination type (presumably because of a copy/paste error).
Tim
Good catch, thanks.
I've committed this patch.
commit 5c021e19e0758e5ad7e47feadbd0632b15f85785
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Sep 18 19:04:25 2017 +0100
PR libstdc++/81468 fix test for duration conversions
PR libstdc++/81468
* testsuite/20_util/duration/cons/dr1177.cc: Fix incorrect test and
improve static assertion messages.
diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc b/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc
index 28c881ccc79..d90cd27f482 100644
--- a/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc
@@ -36,6 +36,6 @@ static_assert(is_constructible<duration<int>, duration<long>>{},
static_assert(!is_constructible<duration<int>, duration<int, ratio<2,3>>>{},
"cannot convert duration to one with different period");
static_assert(is_constructible<duration<float>, duration<int, ratio<2,3>>>{},
- "unless it has a floating-point representation");
-static_assert(is_constructible<duration<float>, duration<int, ratio<1,3>>>{},
- "or a period that is an integral multiple of the original");
+ "... unless the result type has a floating-point representation");
+static_assert(is_constructible<duration<int, ratio<1,3>>, duration<int>>{},
+ "... or the original's period is a multiple of the result's period");