[libcxx-commits] [libcxx] d529e81 - [libc++] Fix compilation error on platforms that don't implement std::tm
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 8 15:11:06 PDT 2022
Author: Louis Dionne
Date: 2022-09-08T18:10:53-04:00
New Revision: d529e8110bdf49ca0f00fe4bfbae7db64a49f70c
URL: https://github.com/llvm/llvm-project/commit/d529e8110bdf49ca0f00fe4bfbae7db64a49f70c
DIFF: https://github.com/llvm/llvm-project/commit/d529e8110bdf49ca0f00fe4bfbae7db64a49f70c.diff
LOG: [libc++] Fix compilation error on platforms that don't implement std::tm
Instead of mentioning tm directly in the definition of __convert_to_tm,
take it as a template argument. As a fly-by also fix incorrect Lit feature
(should have been no-localization instead of libcpp-has-no-localization).
Differential Revision: https://reviews.llvm.org/D133490
Added:
Modified:
libcxx/include/__chrono/convert_to_tm.h
libcxx/include/__chrono/formatter.h
libcxx/test/std/time/time.cal/time.cal.day/time.cal.day.nonmembers/ostream.pass.cpp
libcxx/test/std/time/time.syn/formatter.day.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__chrono/convert_to_tm.h b/libcxx/include/__chrono/convert_to_tm.h
index a5dc3beaa2c0a..169d97b34d112 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -13,7 +13,6 @@
#include <__chrono/day.h>
#include <__concepts/same_as.h>
#include <__config>
-#include <ctime>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -23,17 +22,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER > 17
-template <class _Tp>
-_LIBCPP_HIDE_FROM_ABI tm __convert_to_tm(const _Tp& __value) {
- tm __result = {};
+// Convert a chrono calendar time point to the given tm type,
+// which must have the same properties as std::tm.
+template <class _Tm, class _ChronoCalendarTimePoint>
+_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoCalendarTimePoint& __value) {
+ _Tm __result = {};
# ifdef __GLIBC__
__result.tm_zone = "UTC";
# endif
- if constexpr (same_as<_Tp, chrono::day>)
+ if constexpr (same_as<_ChronoCalendarTimePoint, chrono::day>)
__result.tm_mday = static_cast<unsigned>(__value);
else
- static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
+ static_assert(sizeof(_ChronoCalendarTimePoint) == 0, "Add the missing type specialization");
return __result;
}
diff --git a/libcxx/include/__chrono/formatter.h b/libcxx/include/__chrono/formatter.h
index a38a5538228a2..47c79201e62ef 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -55,7 +55,7 @@ namespace __formatter {
template <class _CharT, class _Tp>
_LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
const _Tp& __value, basic_stringstream<_CharT>& __sstr, basic_string_view<_CharT> __chrono_specs) {
- tm __t = std::__convert_to_tm(__value);
+ tm __t = std::__convert_to_tm<tm>(__value);
const auto& __facet = std::use_facet<time_put<_CharT>>(__sstr.getloc());
for (auto __it = __chrono_specs.begin(); __it != __chrono_specs.end(); ++__it) {
if (*__it == _CharT('%')) {
diff --git a/libcxx/test/std/time/time.cal/time.cal.day/time.cal.day.nonmembers/ostream.pass.cpp b/libcxx/test/std/time/time.cal/time.cal.day/time.cal.day.nonmembers/ostream.pass.cpp
index 255f7a744e54c..d69ec660f1693 100644
--- a/libcxx/test/std/time/time.cal/time.cal.day/time.cal.day.nonmembers/ostream.pass.cpp
+++ b/libcxx/test/std/time/time.cal/time.cal.day/time.cal.day.nonmembers/ostream.pass.cpp
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
-// UNSUPPORTED: libcpp-has-no-localization
+// UNSUPPORTED: no-localization
// UNSUPPORTED: libcpp-has-no-incomplete-format
// TODO FMT Investigate Windows issues.
diff --git a/libcxx/test/std/time/time.syn/formatter.day.pass.cpp b/libcxx/test/std/time/time.syn/formatter.day.pass.cpp
index 3dbc1e9d7b0cc..980b8bae1ddf8 100644
--- a/libcxx/test/std/time/time.syn/formatter.day.pass.cpp
+++ b/libcxx/test/std/time/time.syn/formatter.day.pass.cpp
@@ -6,7 +6,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
-// UNSUPPORTED: libcpp-has-no-localization
+// UNSUPPORTED: no-localization
// UNSUPPORTED: libcpp-has-no-incomplete-format
// TODO FMT Investigate Windows issues.
More information about the libcxx-commits
mailing list