Tested on Linux-x64
Implementation of resolution for C++17 GB50
2017-02-12 Dinka Ranns <[email protected]>
C++17 GB50 resolution
* libstdc++-v3/include/std/chrono:
(duration::operator++()): Add constexpr.
(duration::operator++(int)): Likewise
(duration::operator--()): Likewise
(duration::operator--(int)): Likewise
(duration::operator+=(const duration&)): Likewise
(duration::operator-=(const duration&)): Likewise
(duration::operator*=(const rep&)): Likewise
(duration::operator/=(const rep&)): Likewise
(duration::operator%=(const rep&)): Likewise
(duration::operator%=(const duration&)): Likewise
(time_point::operator+=(const duration&)): Likewise
(time_point::operator-=(const duration&)): Likewise
* libstdc++-v3/testsuite/20_util/duration/arithmetic/constexpr.cc:
new tests
* libstdc++-v3/testsuite/20_util/time_point/arithmetic/constexpr.cc: new
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index ceae7f8..6a6995c 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -349,50 +349,50 @@ _GLIBCXX_END_NAMESPACE_VERSION
operator-() const
{ return duration(-__r); }
- duration&
+ constexpr duration&
operator++()
{
++__r;
return *this;
}
- duration
+ constexpr duration
operator++(int)
{ return duration(__r++); }
- duration&
+ constexpr duration&
operator--()
{
--__r;
return *this;
}
- duration
+ constexpr duration
operator--(int)
{ return duration(__r--); }
- duration&
+ constexpr duration&
operator+=(const duration& __d)
{
__r += __d.count();
return *this;
}
- duration&
+ constexpr duration&
operator-=(const duration& __d)
{
__r -= __d.count();
return *this;
}
- duration&
+ constexpr duration&
operator*=(const rep& __rhs)
{
__r *= __rhs;
return *this;
}
- duration&
+ constexpr duration&
operator/=(const rep& __rhs)
{
__r /= __rhs;
@@ -401,7 +401,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
// DR 934.
template<typename _Rep2 = rep>
- typename enable_if<!treat_as_floating_point<_Rep2>::value,
+ constexpr typename enable_if<!treat_as_floating_point<_Rep2>::value,
duration&>::type
operator%=(const rep& __rhs)
{
@@ -410,7 +410,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
}
template<typename _Rep2 = rep>
- typename enable_if<!treat_as_floating_point<_Rep2>::value,
+ constexpr typename enable_if<!treat_as_floating_point<_Rep2>::value,
duration&>::type
operator%=(const duration& __d)
{
@@ -631,14 +631,14 @@ _GLIBCXX_END_NAMESPACE_VERSION
{ return __d; }
// arithmetic
- time_point&
+ constexpr time_point&
operator+=(const duration& __dur)
{
__d += __dur;
return *this;
}
- time_point&
+ constexpr time_point&
operator-=(const duration& __dur)
{
__d -= __dur;
diff --git a/libstdc++-v3/testsuite/20_util/duration/arithmetic/constexpr.cc
b/libstdc++-v3/testsuite/20_util/duration/arithmetic/constexpr.cc
index 285f941..1128a52 100644
--- a/libstdc++-v3/testsuite/20_util/duration/arithmetic/constexpr.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/arithmetic/constexpr.cc
@@ -19,11 +19,31 @@
#include <chrono>
#include <testsuite_common_types.h>
+constexpr auto test_operators()
+{
+ std::chrono::nanoseconds d1 { };
+ d1++;
+ ++d1;
+ d1--;
+ --d1;
+
+ auto d2(d1);
+
+ d1+=d2;
+ d1-=d2;
+ d1*=1;
+ d1/=1;
+ d1%=1;
+ d1%=d2;
+
+ return d1;
+}
int main()
{
constexpr std::chrono::nanoseconds d1 { };
constexpr auto d2(+d1);
constexpr auto d3(-d2);
+ constexpr auto d4 = test_operators();
return 0;
}
diff --git a/libstdc++-v3/testsuite/20_util/time_point/arithmetic/constexpr.cc
b/libstdc++-v3/testsuite/20_util/time_point/arithmetic/constexpr.cc
new file mode 100644
index 0000000..e87a226
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/time_point/arithmetic/constexpr.cc
@@ -0,0 +1,39 @@
+// { dg-do compile { target c++11 } }
+
+// Copyright (C) 2011-2016 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/>.
+
+#include <chrono>
+#include <testsuite_common_types.h>
+constexpr auto test_operators()
+{
+ using namespace std::chrono;
+ nanoseconds d1 { };
+ time_point<system_clock> c1 { };
+
+ c1+=d1;
+ c1-=d1;
+
+
+ return 11;
+}
+int main()
+{
+ constexpr auto a = test_operators();
+
+ return 0;
+}