diff options
author | Eric Fiselier <eric@efcs.ca> | 2018-12-21 03:54:57 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2018-12-21 03:54:57 +0000 |
commit | 114384b825673d9c709431269afc5edde88930f0 (patch) | |
tree | 208a671acfab807dbfd895ca256879d6b8c35962 /libcxx | |
parent | 252c8de76c05fa99fd1b3bcf4ff5a6ff1fe9e763 (diff) |
Implement LWG 3145: file_clock breaks ABI for C++17 implementations.
This patch adds std::chrono::file_clock, but without breaking the
existing ABI for std::filesystem.
Diffstat (limited to 'libcxx')
7 files changed, 171 insertions, 32 deletions
diff --git a/libcxx/include/chrono b/libcxx/include/chrono index e99e3c74c74..a5bb9afa8b2 100644 --- a/libcxx/include/chrono +++ b/libcxx/include/chrono @@ -808,6 +808,9 @@ constexpr chrono::year operator ""y(unsigned lo _LIBCPP_PUSH_MACROS #include <__undef_macros> +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +struct _FilesystemClock; +_LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD @@ -1581,9 +1584,13 @@ typedef system_clock high_resolution_clock; #endif #if _LIBCPP_STD_VER > 17 +// [time.clock.file], type file_clock +using file_clock = _VSTD_FS::_FilesystemClock; -struct _LIBCPP_TYPE_VIS last_spec { explicit last_spec() = default; }; +template<class _Duration> +using file_time = time_point<file_clock, _Duration>; +struct _LIBCPP_TYPE_VIS last_spec { explicit last_spec() = default; }; class _LIBCPP_TYPE_VIS day { private: @@ -2689,6 +2696,40 @@ namespace chrono { // hoist the literals into namespace std::chrono _LIBCPP_END_NAMESPACE_STD +#ifndef _LIBCPP_CXX03_LANG +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +struct _FilesystemClock { +#if !defined(_LIBCPP_HAS_NO_INT128) + typedef __int128_t rep; + typedef nano period; +#else + typedef long long rep; + typedef nano period; +#endif + + typedef chrono::duration<rep, period> duration; + typedef chrono::time_point<_FilesystemClock> time_point; + + static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; + + _LIBCPP_FUNC_VIS static time_point now() noexcept; + + _LIBCPP_INLINE_VISIBILITY + static time_t to_time_t(const time_point& __t) noexcept { + typedef chrono::duration<rep> __secs; + return time_t( + chrono::duration_cast<__secs>(__t.time_since_epoch()).count()); + } + + _LIBCPP_INLINE_VISIBILITY + static time_point from_time_t(time_t __t) noexcept { + typedef chrono::duration<rep> __secs; + return time_point(__secs(__t)); + } +}; +_LIBCPP_END_NAMESPACE_FILESYSTEM +#endif // !_LIBCPP_CXX03_LANG + _LIBCPP_POP_MACROS #endif // _LIBCPP_CHRONO diff --git a/libcxx/include/filesystem b/libcxx/include/filesystem index 339bb252fce..06a0eb33c4e 100644 --- a/libcxx/include/filesystem +++ b/libcxx/include/filesystem @@ -259,36 +259,6 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM -struct _FilesystemClock { -#if !defined(_LIBCPP_HAS_NO_INT128) - typedef __int128_t rep; - typedef nano period; -#else - typedef long long rep; - typedef nano period; -#endif - - typedef chrono::duration<rep, period> duration; - typedef chrono::time_point<_FilesystemClock> time_point; - - static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; - - _LIBCPP_FUNC_VIS static time_point now() noexcept; - - _LIBCPP_INLINE_VISIBILITY - static time_t to_time_t(const time_point& __t) noexcept { - typedef chrono::duration<rep> __secs; - return time_t( - chrono::duration_cast<__secs>(__t.time_since_epoch()).count()); - } - - _LIBCPP_INLINE_VISIBILITY - static time_point from_time_t(time_t __t) noexcept { - typedef chrono::duration<rep> __secs; - return time_point(__secs(__t)); - } -}; - typedef chrono::time_point<_FilesystemClock> file_time_type; struct _LIBCPP_TYPE_VIS space_info { diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp new file mode 100644 index 00000000000..275faa6288d --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.file/consistency.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// +// TODO: Remove this when filesystem gets integrated into the dylib +// REQUIRES: c++filesystem + +// <chrono> + +// file_clock + +// check clock invariants + +#include <chrono> + +template <class T> +void test(const T &) {} + +int main() +{ + typedef std::chrono::system_clock C; + static_assert((std::is_same<C::rep, C::duration::rep>::value), ""); + static_assert((std::is_same<C::period, C::duration::period>::value), ""); + static_assert((std::is_same<C::duration, C::time_point::duration>::value), ""); + static_assert((std::is_same<C::time_point::clock, C>::value), ""); + static_assert((C::is_steady || !C::is_steady), ""); + test(std::chrono::system_clock::is_steady); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp new file mode 100644 index 00000000000..955e3ebe9d5 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.file/file_time.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// <chrono> + +// file_time + +#include <chrono> + +#include "test_macros.h" + +template <class Dur> +void test() { + ASSERT_SAME_TYPE(std::chrono::file_time<Dur>, std::chrono::time_point<std::chrono::file_clock, Dur>); +} + +int main() { + test<std::chrono::nanoseconds>(); + test<std::chrono::minutes>(); + test<std::chrono::hours>(); +}
\ No newline at end of file diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.file/now.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.file/now.pass.cpp new file mode 100644 index 00000000000..69dfa918093 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.file/now.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// TODO: Remove this when filesystem gets integrated into the dylib +// REQUIRES: c++filesystem + +// <chrono> + +// file_clock + +// static time_point now() noexcept; + +#include <chrono> +#include <cassert> + +#include "test_macros.h" + +int main() +{ + typedef std::chrono::file_clock C; + ASSERT_NOEXCEPT(C::now()); + + C::time_point t1 = C::now(); + assert(t1.time_since_epoch().count() != 0); + assert(C::time_point::min() < t1); + assert(C::time_point::max() > t1); +} diff --git a/libcxx/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp b/libcxx/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp new file mode 100644 index 00000000000..c0fa0b5beda --- /dev/null +++ b/libcxx/test/std/utilities/time/time.clock/time.clock.file/rep_signed.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// TODO: Remove this when filesystem gets integrated into the dylib +// REQUIRES: c++filesystem + +// <chrono> + +// file_clock + +// rep should be signed + +#include <chrono> +#include <cassert> + +int main() +{ + static_assert(std::is_signed<std::chrono::file_clock::rep>::value, ""); + assert(std::chrono::file_clock::duration::min() < + std::chrono::file_clock::duration::zero()); +} diff --git a/libcxx/www/cxx2a_status.html b/libcxx/www/cxx2a_status.html index 25e6cdfe4e4..88aa56e38a8 100644 --- a/libcxx/www/cxx2a_status.html +++ b/libcxx/www/cxx2a_status.html @@ -282,7 +282,7 @@ <tr><td><a href="https://wg21.link/LWG3132">3132</a></td><td>Library needs to ban macros named <tt>expects</tt> or <tt>ensures</tt></td><td>San Diego</td><td><i>Nothing to do</i></td></tr> <tr><td><a href="https://wg21.link/LWG3134">3134</a></td><td>[fund.ts.v3] LFTSv3 contains extraneous [meta] variable templates that should have been deleted by P09961</td><td>San Diego</td><td>Resolved by P1210R0</td></tr> <tr><td><a href="https://wg21.link/LWG3137">3137</a></td><td>Header for <tt>__cpp_lib_to_chars</tt></td><td>San Diego</td><td><i>We've already made the update; but we don't support all the test macros. When we do, this will be closed</i></td></tr> - <tr><td><a href="https://wg21.link/LWG3145">3145</a></td><td><tt>file_clock</tt> breaks ABI for C++17 implementations</td><td>San Diego</td><td></td></tr> + <tr><td><a href="https://wg21.link/LWG3145">3145</a></td><td><tt>file_clock</tt> breaks ABI for C++17 implementations</td><td>San Diego</td><td>Complete</td></tr> <tr><td><a href="https://wg21.link/LWG3147">3147</a></td><td>Definitions of "likely" and "unlikely" are likely to cause problems</td><td>San Diego</td><td></td></tr> <tr><td><a href="https://wg21.link/LWG3148">3148</a></td><td><tt><concepts></tt> should be freestanding</td><td>San Diego</td><td></td></tr> <tr><td><a href="https://wg21.link/LWG3153">3153</a></td><td><tt>Common</tt> and <tt>common_type</tt> have too little in common</td><td>San Diego</td><td></td></tr> |