[PATCH] PR libstdc++/81468 constrain std::chrono::time_point constructor

Jonathan Wakely jwakely@redhat.com
Mon Sep 18 20:00:00 GMT 2017


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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 1365 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20170918/988099e8/attachment.bin>


More information about the Libstdc++ mailing list