Skip to content

Commit

Permalink
Last week, someone noted that a couple of the time_point member funct…
Browse files Browse the repository at this point in the history
…ions 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.

llvm-svn: 340992
  • Loading branch information
mclow committed Aug 29, 2018
1 parent 9397c2a commit d0ab67f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
26 changes: 14 additions & 12 deletions libcxx/include/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -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++(); // 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 duration& operator-=(const duration& d);
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);
duration& operator/=(const rep& rhs);
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d0ab67f

Please sign in to comment.