Skip to content

Commit

Permalink
<format>: compile time checks (#2221)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Schellenberger Costa <mschellenbergercosta@gmail.com>
Co-authored-by: Stephan T. Lavavej <stl@microsoft.com>
  • Loading branch information
3 people committed Dec 17, 2021
1 parent 568a21b commit 9265c51
Show file tree
Hide file tree
Showing 12 changed files with 443 additions and 217 deletions.
76 changes: 38 additions & 38 deletions stl/inc/chrono
Expand Up @@ -5829,11 +5829,11 @@ namespace chrono {
struct _Chrono_formatter {
_Chrono_formatter() = default;

explicit _Chrono_formatter(const basic_string_view<_CharT> _Time_zone_abbreviation_)
constexpr explicit _Chrono_formatter(const basic_string_view<_CharT> _Time_zone_abbreviation_)
: _Time_zone_abbreviation{_Time_zone_abbreviation_} {}

template <class _Ty>
_NODISCARD auto _Parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
_NODISCARD constexpr auto _Parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
_Chrono_specs_setter<_CharT, basic_format_parse_context<_CharT>> _Callback{_Specs, _Parse_ctx};
const auto _It =
_Parse_chrono_format_specs(_Parse_ctx._Unchecked_begin(), _Parse_ctx._Unchecked_end(), _Callback);
Expand Down Expand Up @@ -5867,39 +5867,39 @@ namespace chrono {
return _Res_iter;
}

static void _Check_modifier(const char _Type, const char _Modifier) {
if (_Modifier == '\0') {
return;
}
enum _Allowed_bit : uint8_t { _E_mod = 1, _O_mod = 2, _EO_mod = _E_mod | _O_mod };

enum _Allowed_bit : uint8_t { _E_mod = 1, _O_mod = 2, _EO_mod = _E_mod | _O_mod };
struct _Table_entry {
char _Type;
_Allowed_bit _Allowed;
};

struct _Table_entry {
char _Type;
_Allowed_bit _Allowed;
};
static constexpr _Table_entry _Table[] = {
{'c', _E_mod},
{'C', _E_mod},
{'d', _O_mod},
{'e', _O_mod},
{'H', _O_mod},
{'I', _O_mod},
{'m', _O_mod},
{'M', _O_mod},
{'S', _O_mod},
{'u', _O_mod},
{'U', _O_mod},
{'V', _O_mod},
{'w', _O_mod},
{'W', _O_mod},
{'x', _E_mod},
{'X', _E_mod},
{'y', _EO_mod},
{'Y', _E_mod},
{'z', _EO_mod},
};

static constexpr _Table_entry _Table[] = {
{'c', _E_mod},
{'C', _E_mod},
{'d', _O_mod},
{'e', _O_mod},
{'H', _O_mod},
{'I', _O_mod},
{'m', _O_mod},
{'M', _O_mod},
{'S', _O_mod},
{'u', _O_mod},
{'U', _O_mod},
{'V', _O_mod},
{'w', _O_mod},
{'W', _O_mod},
{'x', _E_mod},
{'X', _E_mod},
{'y', _EO_mod},
{'Y', _E_mod},
{'z', _EO_mod},
};
static constexpr void _Check_modifier(const char _Type, const char _Modifier) {
if (_Modifier == '\0') {
return;
}

const _Allowed_bit _Mod = _Modifier == 'E' ? _E_mod : _O_mod;

Expand Down Expand Up @@ -6329,7 +6329,7 @@ namespace chrono {

template <class _Ty, class _CharT>
struct _Fill_tm_formatter {
auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
constexpr auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
return _Impl.template _Parse<_Ty>(_Parse_ctx);
}

Expand Down Expand Up @@ -6420,7 +6420,7 @@ struct formatter<_CHRONO local_info, _CharT> //

template <class _Duration, class _CharT>
struct formatter<_CHRONO sys_time<_Duration>, _CharT> {
auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
constexpr auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
return _Impl.template _Parse<_CHRONO sys_time<_Duration>>(_Parse_ctx);
}

Expand All @@ -6435,7 +6435,7 @@ private:

template <class _Duration, class _CharT>
struct formatter<_CHRONO utc_time<_Duration>, _CharT> {
auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
constexpr auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
return _Impl.template _Parse<_CHRONO utc_time<_Duration>>(_Parse_ctx);
}

Expand All @@ -6451,7 +6451,7 @@ private:

template <class _Duration, class _CharT>
struct formatter<_CHRONO tai_time<_Duration>, _CharT> {
auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
constexpr auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
return _Impl.template _Parse<_CHRONO tai_time<_Duration>>(_Parse_ctx);
}

Expand All @@ -6470,7 +6470,7 @@ private:

template <class _Duration, class _CharT>
struct formatter<_CHRONO gps_time<_Duration>, _CharT> {
auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
constexpr auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
return _Impl.template _Parse<_CHRONO gps_time<_Duration>>(_Parse_ctx);
}

Expand All @@ -6489,7 +6489,7 @@ private:

template <class _Duration, class _CharT>
struct formatter<_CHRONO file_time<_Duration>, _CharT> {
auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
constexpr auto parse(basic_format_parse_context<_CharT>& _Parse_ctx) {
return _Impl.template _Parse<_CHRONO file_time<_Duration>>(_Parse_ctx);
}

Expand Down

0 comments on commit 9265c51

Please sign in to comment.