Skip to content

Commit 87d56c5

Browse files
authored
[libc++][modules] Guard carved-out headers more consistently (llvm#108637)
Several headers that should not be provided when localization or threads are disabled were not guarded. That works until one tries to build with modules and these headers get pulled in. Note that this could be cleaned up further into something more systematic, but this patch solves the immediate problems I ran into with the monolithic modulemap and doesn't create any new inconsistency that wasn't already there.
1 parent 1881f64 commit 87d56c5

15 files changed

+644
-590
lines changed

libcxx/include/__chrono/formatter.h

Lines changed: 83 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,58 @@
1010
#ifndef _LIBCPP___CHRONO_FORMATTER_H
1111
#define _LIBCPP___CHRONO_FORMATTER_H
1212

13-
#include <__algorithm/ranges_copy.h>
14-
#include <__chrono/calendar.h>
15-
#include <__chrono/concepts.h>
16-
#include <__chrono/convert_to_tm.h>
17-
#include <__chrono/day.h>
18-
#include <__chrono/duration.h>
19-
#include <__chrono/file_clock.h>
20-
#include <__chrono/hh_mm_ss.h>
21-
#include <__chrono/local_info.h>
22-
#include <__chrono/month.h>
23-
#include <__chrono/month_weekday.h>
24-
#include <__chrono/monthday.h>
25-
#include <__chrono/ostream.h>
26-
#include <__chrono/parser_std_format_spec.h>
27-
#include <__chrono/statically_widen.h>
28-
#include <__chrono/sys_info.h>
29-
#include <__chrono/system_clock.h>
30-
#include <__chrono/time_point.h>
31-
#include <__chrono/weekday.h>
32-
#include <__chrono/year.h>
33-
#include <__chrono/year_month.h>
34-
#include <__chrono/year_month_day.h>
35-
#include <__chrono/year_month_weekday.h>
36-
#include <__chrono/zoned_time.h>
37-
#include <__concepts/arithmetic.h>
38-
#include <__concepts/same_as.h>
3913
#include <__config>
40-
#include <__format/concepts.h>
41-
#include <__format/format_error.h>
42-
#include <__format/format_functions.h>
43-
#include <__format/format_parse_context.h>
44-
#include <__format/formatter.h>
45-
#include <__format/parser_std_format_spec.h>
46-
#include <__format/write_escaped.h>
47-
#include <__memory/addressof.h>
48-
#include <__type_traits/is_specialization.h>
49-
#include <cmath>
50-
#include <ctime>
51-
#include <limits>
52-
#include <sstream>
53-
#include <string_view>
54-
55-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56-
# pragma GCC system_header
57-
#endif
14+
15+
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
16+
17+
# include <__algorithm/ranges_copy.h>
18+
# include <__chrono/calendar.h>
19+
# include <__chrono/concepts.h>
20+
# include <__chrono/convert_to_tm.h>
21+
# include <__chrono/day.h>
22+
# include <__chrono/duration.h>
23+
# include <__chrono/file_clock.h>
24+
# include <__chrono/hh_mm_ss.h>
25+
# include <__chrono/local_info.h>
26+
# include <__chrono/month.h>
27+
# include <__chrono/month_weekday.h>
28+
# include <__chrono/monthday.h>
29+
# include <__chrono/ostream.h>
30+
# include <__chrono/parser_std_format_spec.h>
31+
# include <__chrono/statically_widen.h>
32+
# include <__chrono/sys_info.h>
33+
# include <__chrono/system_clock.h>
34+
# include <__chrono/time_point.h>
35+
# include <__chrono/weekday.h>
36+
# include <__chrono/year.h>
37+
# include <__chrono/year_month.h>
38+
# include <__chrono/year_month_day.h>
39+
# include <__chrono/year_month_weekday.h>
40+
# include <__chrono/zoned_time.h>
41+
# include <__concepts/arithmetic.h>
42+
# include <__concepts/same_as.h>
43+
# include <__format/concepts.h>
44+
# include <__format/format_error.h>
45+
# include <__format/format_functions.h>
46+
# include <__format/format_parse_context.h>
47+
# include <__format/formatter.h>
48+
# include <__format/parser_std_format_spec.h>
49+
# include <__format/write_escaped.h>
50+
# include <__memory/addressof.h>
51+
# include <__type_traits/is_specialization.h>
52+
# include <cmath>
53+
# include <ctime>
54+
# include <limits>
55+
# include <sstream>
56+
# include <string_view>
57+
58+
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
59+
# pragma GCC system_header
60+
# endif
5861

5962
_LIBCPP_BEGIN_NAMESPACE_STD
6063

61-
#if _LIBCPP_STD_VER >= 20
64+
# if _LIBCPP_STD_VER >= 20
6265

6366
namespace __formatter {
6467

@@ -139,24 +142,24 @@ __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::hh_mm_ss<
139142
__value.fractional_width);
140143
}
141144

142-
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
143-
!defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
145+
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
146+
!defined(_LIBCPP_HAS_NO_FILESYSTEM)
144147
template <class _CharT, class _Duration, class _TimeZonePtr>
145148
_LIBCPP_HIDE_FROM_ABI void
146149
__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::zoned_time<_Duration, _TimeZonePtr>& __value) {
147150
__formatter::__format_sub_seconds(__sstr, __value.get_local_time().time_since_epoch());
148151
}
149-
# endif
152+
# endif
150153

151154
template <class _Tp>
152155
consteval bool __use_fraction() {
153156
if constexpr (__is_time_point<_Tp>)
154157
return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
155-
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
156-
!defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
158+
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
159+
!defined(_LIBCPP_HAS_NO_FILESYSTEM)
157160
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
158161
return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
159-
# endif
162+
# endif
160163
else if constexpr (chrono::__is_duration<_Tp>::value)
161164
return chrono::hh_mm_ss<_Tp>::fractional_width;
162165
else if constexpr (__is_hh_mm_ss<_Tp>)
@@ -225,16 +228,15 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
225228

226229
template <class _Tp>
227230
_LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] const _Tp& __value) {
228-
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
231+
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
229232
if constexpr (same_as<_Tp, chrono::sys_info>)
230233
return {__value.abbrev, __value.offset};
231-
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
232-
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
234+
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
233235
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
234236
return __formatter::__convert_to_time_zone(__value.get_info());
235-
# endif
237+
# endif
236238
else
237-
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
239+
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
238240
return {"UTC", chrono::seconds{0}};
239241
}
240242

@@ -341,12 +343,12 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
341343
//
342344
// TODO FMT evaluate the comment above.
343345

344-
# if defined(__GLIBC__) || defined(_AIX) || defined(_WIN32)
346+
# if defined(__GLIBC__) || defined(_AIX) || defined(_WIN32)
345347
case _CharT('y'):
346348
// Glibc fails for negative values, AIX for positive values too.
347349
__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), (std::abs(__t.tm_year + 1900)) % 100);
348350
break;
349-
# endif // defined(__GLIBC__) || defined(_AIX) || defined(_WIN32)
351+
# endif // defined(__GLIBC__) || defined(_AIX) || defined(_WIN32)
350352

351353
case _CharT('Y'):
352354
// Depending on the platform's libc the range of supported years is
@@ -442,17 +444,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const _Tp& __value) {
442444
return __value.weekday().ok();
443445
else if constexpr (__is_hh_mm_ss<_Tp>)
444446
return true;
445-
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
447+
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
446448
else if constexpr (same_as<_Tp, chrono::sys_info>)
447449
return true;
448450
else if constexpr (same_as<_Tp, chrono::local_info>)
449451
return true;
450-
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
451-
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
452+
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
452453
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
453454
return true;
454-
# endif
455-
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
455+
# endif
456+
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
456457
else
457458
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
458459
}
@@ -493,17 +494,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_name_ok(const _Tp& __value) {
493494
return __value.weekday().ok();
494495
else if constexpr (__is_hh_mm_ss<_Tp>)
495496
return true;
496-
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
497+
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
497498
else if constexpr (same_as<_Tp, chrono::sys_info>)
498499
return true;
499500
else if constexpr (same_as<_Tp, chrono::local_info>)
500501
return true;
501-
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
502-
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
502+
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
503503
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
504504
return true;
505-
# endif
506-
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
505+
# endif
506+
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
507507
else
508508
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
509509
}
@@ -544,17 +544,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __date_ok(const _Tp& __value) {
544544
return __value.ok();
545545
else if constexpr (__is_hh_mm_ss<_Tp>)
546546
return true;
547-
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
547+
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
548548
else if constexpr (same_as<_Tp, chrono::sys_info>)
549549
return true;
550550
else if constexpr (same_as<_Tp, chrono::local_info>)
551551
return true;
552-
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
553-
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
552+
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
554553
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
555554
return true;
556-
# endif
557-
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
555+
# endif
556+
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
558557
else
559558
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
560559
}
@@ -595,17 +594,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __month_name_ok(const _Tp& __value) {
595594
return __value.month().ok();
596595
else if constexpr (__is_hh_mm_ss<_Tp>)
597596
return true;
598-
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
597+
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
599598
else if constexpr (same_as<_Tp, chrono::sys_info>)
600599
return true;
601600
else if constexpr (same_as<_Tp, chrono::local_info>)
602601
return true;
603-
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
604-
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
602+
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
605603
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
606604
return true;
607-
# endif
608-
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
605+
# endif
606+
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
609607
else
610608
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
611609
}
@@ -943,7 +941,7 @@ struct formatter<chrono::hh_mm_ss<_Duration>, _CharT> : public __formatter_chron
943941
}
944942
};
945943

946-
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
944+
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
947945
template <__fmt_char_type _CharT>
948946
struct formatter<chrono::sys_info, _CharT> : public __formatter_chrono<_CharT> {
949947
public:
@@ -965,8 +963,7 @@ struct formatter<chrono::local_info, _CharT> : public __formatter_chrono<_CharT>
965963
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags{});
966964
}
967965
};
968-
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
969-
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
966+
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
970967
// Note due to how libc++'s formatters are implemented there is no need to add
971968
// the exposition only local-time-format-t abstraction.
972969
template <class _Duration, class _TimeZonePtr, __fmt_char_type _CharT>
@@ -979,12 +976,13 @@ struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT> : public _
979976
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock);
980977
}
981978
};
982-
# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&
983-
// !defined(_LIBCPP_HAS_NO_LOCALIZATION)
984-
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
979+
# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
980+
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
985981

986-
#endif // if _LIBCPP_STD_VER >= 20
982+
# endif // if _LIBCPP_STD_VER >= 20
987983

988984
_LIBCPP_END_NAMESPACE_STD
989985

986+
#endif // !_LIBCPP_HAS_NO_LOCALIZATION
987+
990988
#endif // _LIBCPP___CHRONO_FORMATTER_H

0 commit comments

Comments
 (0)