[libcxx] r340992 - Last week, someone noted that a couple of the time_point member functions were not constexpr. I looked, and they were right. They were made constexpr in p0505, so I looked at all the other bits in that paper to make sure that I didn't miss anything else. There were a couple methods in the synopsis that should have been marked constexpr, but the code was correct.
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 29 16:02:15 PDT 2018
Author: marshall
Date: Wed Aug 29 16:02:15 2018
New Revision: 340992
URL: http://llvm.org/viewvc/llvm-project?rev=340992&view=rev
Log:
Last week, someone noted that a couple of the time_point member functions were not constexpr. I looked, and they were right. They were made constexpr in p0505, so I looked at all the other bits in that paper to make sure that I didn't miss anything else. There were a couple methods in the synopsis that should have been marked constexpr, but the code was correct.
Modified:
libcxx/trunk/include/chrono
libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.cpp
libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.cpp
Modified: libcxx/trunk/include/chrono
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/chrono?rev=340992&r1=340991&r2=340992&view=diff
==============================================================================
--- libcxx/trunk/include/chrono (original)
+++ libcxx/trunk/include/chrono Wed Aug 29 16:02:15 2018
@@ -77,16 +77,18 @@ public:
constexpr common_type<duration>::type operator+() const;
constexpr common_type<duration>::type operator-() const;
- constexpr duration& operator++();
- constexpr duration operator++(int);
- constexpr duration& operator--();
- constexpr duration operator--(int);
-
- constexpr duration& operator+=(const duration& d);
- constexpr duration& operator-=(const duration& d);
-
- duration& operator*=(const rep& rhs);
- duration& operator/=(const rep& rhs);
+ constexpr duration& operator++(); // constexpr in C++17
+ constexpr duration operator++(int); // constexpr in C++17
+ constexpr duration& operator--(); // constexpr in C++17
+ constexpr duration operator--(int); // constexpr in C++17
+
+ constexpr duration& operator+=(const duration& d); // constexpr in C++17
+ constexpr duration& operator-=(const duration& d); // constexpr in C++17
+
+ duration& operator*=(const rep& rhs); // constexpr in C++17
+ duration& operator/=(const rep& rhs); // constexpr in C++17
+ duration& operator%=(const rep& rhs); // constexpr in C++17
+ duration& operator%=(const duration& rhs); // constexpr in C++17
// special values
@@ -127,8 +129,8 @@ public:
// arithmetic
- time_point& operator+=(const duration& d);
- time_point& operator-=(const duration& d);
+ time_point& operator+=(const duration& d); // constexpr in C++17
+ time_point& operator-=(const duration& d); // constexpr in C++17
// special values
@@ -1355,8 +1357,8 @@ public:
// arithmetic
- _LIBCPP_INLINE_VISIBILITY time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
- _LIBCPP_INLINE_VISIBILITY time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
// special values
Modified: libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_%2B%3D.pass.cpp?rev=340992&r1=340991&r2=340992&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_+=.pass.cpp Wed Aug 29 16:02:15 2018
@@ -12,15 +12,35 @@
// time_point
// time_point& operator+=(const duration& d);
+// constexpr in c++17
#include <chrono>
#include <cassert>
+#include "test_macros.h"
+
+#if TEST_STD_VER > 14
+constexpr bool constexpr_test()
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::milliseconds Duration;
+ std::chrono::time_point<Clock, Duration> t(Duration(5));
+ t += Duration(4);
+ return t.time_since_epoch() == Duration(9);
+}
+#endif
+
int main()
{
+ {
typedef std::chrono::system_clock Clock;
typedef std::chrono::milliseconds Duration;
std::chrono::time_point<Clock, Duration> t(Duration(3));
t += Duration(2);
assert(t.time_since_epoch() == Duration(5));
+ }
+
+#if TEST_STD_VER > 14
+ static_assert(constexpr_test(), "");
+#endif
}
Modified: libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_-%3D.pass.cpp?rev=340992&r1=340991&r2=340992&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/time/time.point/time.point.arithmetic/op_-=.pass.cpp Wed Aug 29 16:02:15 2018
@@ -12,15 +12,35 @@
// time_point
// time_point& operator-=(const duration& d);
+// constexpr in c++17
#include <chrono>
#include <cassert>
+#include "test_macros.h"
+
+#if TEST_STD_VER > 14
+constexpr bool constexpr_test()
+{
+ typedef std::chrono::system_clock Clock;
+ typedef std::chrono::milliseconds Duration;
+ std::chrono::time_point<Clock, Duration> t(Duration(5));
+ t -= Duration(4);
+ return t.time_since_epoch() == Duration(1);
+}
+#endif
+
int main()
{
+ {
typedef std::chrono::system_clock Clock;
typedef std::chrono::milliseconds Duration;
std::chrono::time_point<Clock, Duration> t(Duration(3));
t -= Duration(2);
assert(t.time_since_epoch() == Duration(1));
+ }
+
+#if TEST_STD_VER > 14
+ static_assert(constexpr_test(), "");
+#endif
}
More information about the cfe-commits
mailing list