From 77a7bd621f815b96009ea4f9d6c83446191f3524 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 2 Oct 2024 07:24:14 -0700 Subject: [PATCH 1/6] Conform `std::iterator_traits` to [iterator.traits]/1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > In addition, the types > ```c++ > iterator_traits::pointer > iterator_traits::reference > ``` > shall be defined as the iterator’s pointer and reference types; that is, for an iterator object `a` of class type, the same type as `decltype(a.operator->())` and `decltype(*a)`, respectively. The type `iterator_traits::pointer` shall be void for an iterator of class type `I` that does not support `operator->`. Additionally, in the case of an output iterator, the types > ```c++ > iterator_traits::value_type > iterator_traits::difference_type > iterator_traits::reference > ``` > may be defined as `void`. --- include/fmt/format.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 4ad1effd5132..f63aefc91823 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -119,11 +119,12 @@ #endif namespace std { -template <> struct iterator_traits { +template struct iterator_traits> { using iterator_category = output_iterator_tag; - using value_type = char; - using reference = char&; - using difference_type = fmt::appender::difference_type; + using value_type = T; + using difference_type = void; + using pointer = void; + using reference = void; }; } // namespace std From ab453402f7c28c3a68782786d5cb3ced68425a2e Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 2 Oct 2024 08:09:44 -0700 Subject: [PATCH 2/6] Remove unnecessary member types from basic_appender --- include/fmt/base.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index f91f8e825354..84b175c31007 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2382,11 +2382,6 @@ template class basic_appender { detail::buffer* container; public: - using iterator_category = int; - using value_type = T; - using pointer = T*; - using reference = T&; - using difference_type = decltype(pointer() - pointer()); using container_type = detail::buffer; FMT_CONSTEXPR basic_appender(detail::buffer& buf) : container(&buf) {} From 1accf6c0a043fb445cbbfeefdbc1f91a08e3099f Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 2 Oct 2024 08:10:18 -0700 Subject: [PATCH 3/6] Silence narrowing warning in `basic_specs::set_fill_size` --- include/fmt/base.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 84b175c31007..35aa238a2372 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -727,7 +727,8 @@ class basic_specs { char fill_data_[max_fill_size] = {' '}; FMT_CONSTEXPR void set_fill_size(size_t size) { - data_ = (data_ & ~fill_size_mask) | (size << fill_size_shift); + data_ &= ~fill_size_mask; + data_ |= static_cast(size << fill_size_shift); } public: From 2f2e0fe0fc09715080aa321de444c4f21f6aff30 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 2 Oct 2024 10:50:18 -0700 Subject: [PATCH 4/6] Derp: iterator concepts require a non-`void`difference type --- include/fmt/format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index f63aefc91823..46522b6a8708 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -122,7 +122,7 @@ namespace std { template struct iterator_traits> { using iterator_category = output_iterator_tag; using value_type = T; - using difference_type = void; + using difference_type = decltype(static_cast(nullptr) - static_cast(nullptr)); using pointer = void; using reference = void; }; From 9d62f68123bca063731ecf0165a7b024ed9fb9d8 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 2 Oct 2024 10:55:48 -0700 Subject: [PATCH 5/6] Revert "Silence narrowing warning in `basic_specs::set_fill_size`" The warning suppression just triggers another warning on a different compiler. Declare defeat. This reverts commit 1accf6c0a043fb445cbbfeefdbc1f91a08e3099f. --- include/fmt/base.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 35aa238a2372..84b175c31007 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -727,8 +727,7 @@ class basic_specs { char fill_data_[max_fill_size] = {' '}; FMT_CONSTEXPR void set_fill_size(size_t size) { - data_ &= ~fill_size_mask; - data_ |= static_cast(size << fill_size_shift); + data_ = (data_ & ~fill_size_mask) | (size << fill_size_shift); } public: From 17e7a6bf7a1475b3a28ebee78a0e60a64f972294 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 2 Oct 2024 11:20:41 -0700 Subject: [PATCH 6/6] Address clang-format issue --- include/fmt/format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 46522b6a8708..ea902e44fedb 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -122,7 +122,8 @@ namespace std { template struct iterator_traits> { using iterator_category = output_iterator_tag; using value_type = T; - using difference_type = decltype(static_cast(nullptr) - static_cast(nullptr)); + using difference_type = + decltype(static_cast(nullptr) - static_cast(nullptr)); using pointer = void; using reference = void; };