]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR libstdc++/81468 constrain std::chrono::time_point constructor
authorJonathan Wakely <jwakely@redhat.com>
Wed, 13 Sep 2017 15:28:12 +0000 (16:28 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 13 Sep 2017 15:28:12 +0000 (16:28 +0100)
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: r252092

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/chrono
libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/duration/literals/range.cc
libstdc++-v3/testsuite/20_util/time_point/cons/81468.cc [new file with mode: 0644]

index e37ff32c90c74d59e8d0225073fb93154374ca38..42d7b31faa03c4e95bdfa093314f128d7a6e2435 100644 (file)
@@ -1,5 +1,12 @@
 2017-09-13  Jonathan Wakely  <jwakely@redhat.com>
 
+       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
index abe0ca119e6c85d56b1f8b920c05019201d63475..10121b718fbfb4e3581d543c7e949034016c1026 100644 (file)
@@ -558,7 +558,8 @@ _GLIBCXX_END_NAMESPACE_VERSION
        { }
 
        // conversions
-       template<typename _Dur2>
+       template<typename _Dur2,
+                typename = _Require<is_convertible<_Dur2, _Dur>>>
          constexpr time_point(const time_point<clock, _Dur2>& __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 (file)
index 0000000..66ac8e6
--- /dev/null
@@ -0,0 +1,42 @@
+// 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <chrono>
+#include <type_traits>
+
+using namespace std;
+using namespace std::chrono;
+
+// 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");
+static_assert(is_constructible<duration<float>, duration<int, ratio<1,3>>>{},
+    "or a period that is an integral multiple of the original");
index 9cd3215067afea37f459ec1d226813aa18422a56..0f51945255fbe9c03226a44f049170bfec3cd1b2 100644 (file)
@@ -27,5 +27,5 @@ test01()
 
   // std::numeric_limits<int64_t>::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 (file)
index 0000000..4c9d5c2
--- /dev/null
@@ -0,0 +1,35 @@
+// 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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <chrono>
+#include <type_traits>
+
+using namespace std;
+using namespace std::chrono;
+
+template <class Duration>
+    using sys_time = time_point<system_clock, Duration>;
+
+static_assert(is_constructible<sys_time<milliseconds>, sys_time<seconds>>{},
+    "Can construct time_point from one with lower precision duration");
+
+// PR libstdc++/81468 - DR 1177
+static_assert(!is_constructible<sys_time<seconds>, sys_time<milliseconds>>{},
+    "Cannot construct time_point from one with higher precision duration");