From: Jonathan Wakely Date: Wed, 13 Sep 2017 15:20:34 +0000 (+0100) Subject: PR libstdc++/81468 constrain std::chrono::time_point constructor X-Git-Tag: releases/gcc-6.5.0~808 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74755f55a3b0149b4b2ae80ef9e2cef5c2a35bfe;p=thirdparty%2Fgcc.git PR libstdc++/81468 constrain std::chrono::time_point constructor PR libstdc++/81468 * include/std/chrono (time_point(const time_point<_Dur2>&)): Add missing constraint from LWG DR 1177. * testsuite/20_util/duration/cons/dr1177.cc: New. * testsuite/20_util/time_point/cons/81468.cc: New. * testsuite/20_util/duration/literals/range.cc: Update dg-error line. From-SVN: r252091 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1ba0afa34cc4..ff89d3a79daa 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2017-09-13 Jonathan Wakely + PR libstdc++/81468 + * include/std/chrono (time_point(const time_point<_Dur2>&)): Add + missing constraint from LWG DR 1177. + * testsuite/20_util/duration/cons/dr1177.cc: New. + * testsuite/20_util/time_point/cons/81468.cc: New. + * testsuite/20_util/duration/literals/range.cc: Update dg-error line. + * doc/doxygen/mainpage.html: Fix broken URLs. PR libstdc++/81835 diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index b0a6df9ce8f4..b4f5f10a1649 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -558,7 +558,8 @@ _GLIBCXX_END_NAMESPACE_VERSION { } // conversions - template + template>> constexpr time_point(const time_point& __t) : __d(__t.time_since_epoch()) { } diff --git a/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc b/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc new file mode 100644 index 000000000000..28c881ccc796 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile { target c++11 } } + +#include +#include + +using namespace std; +using namespace std::chrono; + +// DR 1177 +static_assert(is_constructible, duration>{}, + "can convert duration with one floating point rep to another"); +static_assert(is_constructible, duration>{}, + "can convert duration with integral rep to one with floating point rep"); +static_assert(!is_constructible, duration>{}, + "cannot convert duration with floating point rep to one with integral rep"); +static_assert(is_constructible, duration>{}, + "can convert duration with one integral rep to another"); + +static_assert(!is_constructible, duration>>{}, + "cannot convert duration to one with different period"); +static_assert(is_constructible, duration>>{}, + "unless it has a floating-point representation"); +static_assert(is_constructible, duration>>{}, + "or a period that is an integral multiple of the original"); diff --git a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc b/libstdc++-v3/testsuite/20_util/duration/literals/range.cc index 807b291f8d2e..acbfab009921 100644 --- a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc +++ b/libstdc++-v3/testsuite/20_util/duration/literals/range.cc @@ -27,5 +27,5 @@ test01() // std::numeric_limits::max() == 9223372036854775807; auto h = 9223372036854775808h; - // { dg-error "cannot be represented" "" { target *-*-* } 797 } + // { dg-error "cannot be represented" "" { target *-*-* } 798 } } diff --git a/libstdc++-v3/testsuite/20_util/time_point/cons/81468.cc b/libstdc++-v3/testsuite/20_util/time_point/cons/81468.cc new file mode 100644 index 000000000000..30d1c4a5ac73 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/cons/81468.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile { target c++11 } } + +#include +#include + +using namespace std; +using namespace std::chrono; + +template + using sys_time = time_point; + +static_assert(is_constructible, sys_time>{}, + "Can construct time_point from one with lower precision duration"); + +// PR libstdc++/81468 - DR 1177 +static_assert(!is_constructible, sys_time>{}, + "Cannot construct time_point from one with higher precision duration");