[libc++][format] Fixes vector<bool> requirements.

Makes sure the formatter for the vector<bool>::reference is enabled
when only the header <vector> is included. Before this change it
required <vector> and <format> to be included. This violated the
requirements in the Standard.

Fixes: https://llvm.org/PR61314

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D149543
This commit is contained in:
Mark de Wever 2023-04-20 20:53:46 +02:00
parent 7b7be685d4
commit 7e6bcb35a8
12 changed files with 80 additions and 26 deletions

View File

@ -69,6 +69,11 @@ Deprecations and Removals
- ``<algorithm>`` no longer includes ``<chrono>`` in any C++ version (it was prevously included in C++17 and earlier).
- ``<string>`` no longer includes ``<vector>`` in any C++ version (it was prevously included in C++20 and earlier).
- ``<string>``, ``<string_view>``, and ``<mutex>`` no longer include ``<functional>``
in any C++ version (it was prevously included in C++20 and earlier).
- The headers ``<experimental/algorithm>`` and ``<experimental/functional>`` have been removed, since all the contents
have been implemented in namespace ``std`` for at least two releases.

View File

@ -715,7 +715,6 @@ _LIBCPP_POP_MACROS
# include <cstdlib>
# include <cstring>
# include <ctime>
# include <functional>
# include <initializer_list>
# include <new>
# include <stdexcept>

View File

@ -4389,13 +4389,11 @@ _LIBCPP_POP_MACROS
# include <algorithm>
# include <concepts>
# include <cstdlib>
# include <functional>
# include <iterator>
# include <new>
# include <type_traits>
# include <typeinfo>
# include <utility>
# include <vector>
#endif
#endif // _LIBCPP_STRING

View File

@ -1047,7 +1047,6 @@ _LIBCPP_POP_MACROS
# include <algorithm>
# include <concepts>
# include <cstdlib>
# include <functional>
# include <iterator>
# include <type_traits>
#endif

View File

@ -293,6 +293,7 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
#include <__debug>
#include <__format/enable_insertable.h>
#include <__format/formatter.h>
#include <__format/formatter_bool.h>
#include <__functional/hash.h>
#include <__functional/unary_function.h>
#include <__iterator/advance.h>
@ -3325,7 +3326,7 @@ inline constexpr bool __format::__enable_insertable<vector<wchar_t>> = true;
#endif // _LIBCPP_STD_VER >= 20
#if _LIBCPP_STD_VER >= 23
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) && _LIBCPP_STD_VER >= 23
template <class _Tp, class CharT>
// Since is-vector-bool-reference is only used once it's inlined here.
requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>>
@ -3344,7 +3345,7 @@ public:
return __underlying_.format(__ref, __ctx);
}
};
#endif // _LIBCPP_STD_VER >= 23
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) && _LIBCPP_STD_VER >= 23
_LIBCPP_END_NAMESPACE_STD

View File

@ -575,7 +575,6 @@ mutex cstdint
mutex cstdlib
mutex cstring
mutex ctime
mutex functional
mutex initializer_list
mutex iosfwd
mutex limits
@ -805,7 +804,6 @@ string cstdio
string cstdlib
string cstring
string cwchar
string functional
string initializer_list
string iosfwd
string iterator
@ -817,7 +815,6 @@ string tuple
string type_traits
string typeinfo
string utility
string vector
string version
string_view algorithm
string_view compare
@ -828,7 +825,6 @@ string_view cstdio
string_view cstdlib
string_view cstring
string_view cwchar
string_view functional
string_view initializer_list
string_view iosfwd
string_view iterator
@ -964,7 +960,9 @@ variant typeinfo
variant utility
variant version
vector algorithm
vector array
vector atomic
vector cerrno
vector climits
vector compare
vector concepts
@ -975,8 +973,11 @@ vector cstring
vector initializer_list
vector iosfwd
vector limits
vector locale
vector new
vector stdexcept
vector string
vector string_view
vector tuple
vector type_traits
vector typeinfo

1 algorithm atomic
575 mutex cstdlib
576 mutex cstring
577 mutex ctime
mutex functional
578 mutex initializer_list
579 mutex iosfwd
580 mutex limits
804 string cstdlib
805 string cstring
806 string cwchar
string functional
807 string initializer_list
808 string iosfwd
809 string iterator
815 string type_traits
816 string typeinfo
817 string utility
string vector
818 string version
819 string_view algorithm
820 string_view compare
825 string_view cstdlib
826 string_view cstring
827 string_view cwchar
string_view functional
828 string_view initializer_list
829 string_view iosfwd
830 string_view iterator
960 variant utility
961 variant version
962 vector algorithm
963 vector array
964 vector atomic
965 vector cerrno
966 vector climits
967 vector compare
968 vector concepts
973 vector initializer_list
974 vector iosfwd
975 vector limits
976 vector locale
977 vector new
978 vector stdexcept
979 vector string
980 vector string_view
981 vector tuple
982 vector type_traits
983 vector typeinfo

View File

@ -575,7 +575,6 @@ mutex cstdint
mutex cstdlib
mutex cstring
mutex ctime
mutex functional
mutex initializer_list
mutex iosfwd
mutex limits
@ -806,7 +805,6 @@ string cstdio
string cstdlib
string cstring
string cwchar
string functional
string initializer_list
string iosfwd
string iterator
@ -818,7 +816,6 @@ string tuple
string type_traits
string typeinfo
string utility
string vector
string version
string_view algorithm
string_view compare
@ -829,7 +826,6 @@ string_view cstdio
string_view cstdlib
string_view cstring
string_view cwchar
string_view functional
string_view initializer_list
string_view iosfwd
string_view iterator
@ -965,7 +961,9 @@ variant typeinfo
variant utility
variant version
vector algorithm
vector array
vector atomic
vector cerrno
vector climits
vector compare
vector concepts
@ -976,8 +974,11 @@ vector cstring
vector initializer_list
vector iosfwd
vector limits
vector locale
vector new
vector stdexcept
vector string
vector string_view
vector tuple
vector type_traits
vector typeinfo

1 algorithm atomic
575 mutex cstdlib
576 mutex cstring
577 mutex ctime
mutex functional
578 mutex initializer_list
579 mutex iosfwd
580 mutex limits
805 string cstdlib
806 string cstring
807 string cwchar
string functional
808 string initializer_list
809 string iosfwd
810 string iterator
816 string type_traits
817 string typeinfo
818 string utility
string vector
819 string version
820 string_view algorithm
821 string_view compare
826 string_view cstdlib
827 string_view cstring
828 string_view cwchar
string_view functional
829 string_view initializer_list
830 string_view iosfwd
831 string_view iterator
961 variant utility
962 variant version
963 vector algorithm
964 vector array
965 vector atomic
966 vector cerrno
967 vector climits
968 vector compare
969 vector concepts
974 vector initializer_list
975 vector iosfwd
976 vector limits
977 vector locale
978 vector new
979 vector stdexcept
980 vector string
981 vector string_view
982 vector tuple
983 vector type_traits
984 vector typeinfo

View File

@ -577,7 +577,6 @@ mutex cstdint
mutex cstdlib
mutex cstring
mutex ctime
mutex functional
mutex initializer_list
mutex iosfwd
mutex limits
@ -808,7 +807,6 @@ string cstdio
string cstdlib
string cstring
string cwchar
string functional
string initializer_list
string iosfwd
string iterator
@ -820,7 +818,6 @@ string tuple
string type_traits
string typeinfo
string utility
string vector
string version
string_view algorithm
string_view compare
@ -831,7 +828,6 @@ string_view cstdio
string_view cstdlib
string_view cstring
string_view cwchar
string_view functional
string_view initializer_list
string_view iosfwd
string_view iterator
@ -967,7 +963,9 @@ variant typeinfo
variant utility
variant version
vector algorithm
vector array
vector atomic
vector cerrno
vector climits
vector compare
vector concepts
@ -978,8 +976,11 @@ vector cstring
vector initializer_list
vector iosfwd
vector limits
vector locale
vector new
vector stdexcept
vector string
vector string_view
vector tuple
vector type_traits
vector typeinfo

1 algorithm atomic
577 mutex cstdlib
578 mutex cstring
579 mutex ctime
mutex functional
580 mutex initializer_list
581 mutex iosfwd
582 mutex limits
807 string cstdlib
808 string cstring
809 string cwchar
string functional
810 string initializer_list
811 string iosfwd
812 string iterator
818 string type_traits
819 string typeinfo
820 string utility
string vector
821 string version
822 string_view algorithm
823 string_view compare
828 string_view cstdlib
829 string_view cstring
830 string_view cwchar
string_view functional
831 string_view initializer_list
832 string_view iosfwd
833 string_view iterator
963 variant utility
964 variant version
965 vector algorithm
966 vector array
967 vector atomic
968 vector cerrno
969 vector climits
970 vector compare
971 vector concepts
976 vector initializer_list
977 vector iosfwd
978 vector limits
979 vector locale
980 vector new
981 vector stdexcept
982 vector string
983 vector string_view
984 vector tuple
985 vector type_traits
986 vector typeinfo

View File

@ -577,7 +577,6 @@ mutex cstdint
mutex cstdlib
mutex cstring
mutex ctime
mutex functional
mutex initializer_list
mutex iosfwd
mutex limits
@ -808,7 +807,6 @@ string cstdio
string cstdlib
string cstring
string cwchar
string functional
string initializer_list
string iosfwd
string iterator
@ -820,7 +818,6 @@ string tuple
string type_traits
string typeinfo
string utility
string vector
string version
string_view algorithm
string_view compare
@ -831,7 +828,6 @@ string_view cstdio
string_view cstdlib
string_view cstring
string_view cwchar
string_view functional
string_view initializer_list
string_view iosfwd
string_view iterator
@ -967,7 +963,9 @@ variant typeinfo
variant utility
variant version
vector algorithm
vector array
vector atomic
vector cerrno
vector climits
vector compare
vector concepts
@ -978,8 +976,11 @@ vector cstring
vector initializer_list
vector iosfwd
vector limits
vector locale
vector new
vector stdexcept
vector string
vector string_view
vector tuple
vector type_traits
vector typeinfo

1 algorithm atomic
577 mutex cstdlib
578 mutex cstring
579 mutex ctime
mutex functional
580 mutex initializer_list
581 mutex iosfwd
582 mutex limits
807 string cstdlib
808 string cstring
809 string cwchar
string functional
810 string initializer_list
811 string iosfwd
812 string iterator
818 string type_traits
819 string typeinfo
820 string utility
string vector
821 string version
822 string_view algorithm
823 string_view compare
828 string_view cstdlib
829 string_view cstring
830 string_view cwchar
string_view functional
831 string_view initializer_list
832 string_view iosfwd
833 string_view iterator
963 variant utility
964 variant version
965 vector algorithm
966 vector array
967 vector atomic
968 vector cerrno
969 vector climits
970 vector compare
971 vector concepts
976 vector initializer_list
977 vector iosfwd
978 vector limits
979 vector locale
980 vector new
981 vector stdexcept
982 vector string
983 vector string_view
984 vector tuple
985 vector type_traits
986 vector typeinfo

View File

@ -583,7 +583,6 @@ mutex cstdint
mutex cstdlib
mutex cstring
mutex ctime
mutex functional
mutex initializer_list
mutex iosfwd
mutex limits
@ -814,7 +813,6 @@ string cstdio
string cstdlib
string cstring
string cwchar
string functional
string initializer_list
string iosfwd
string iterator
@ -826,7 +824,6 @@ string tuple
string type_traits
string typeinfo
string utility
string vector
string version
string_view algorithm
string_view compare
@ -837,7 +834,6 @@ string_view cstdio
string_view cstdlib
string_view cstring
string_view cwchar
string_view functional
string_view initializer_list
string_view iosfwd
string_view iterator
@ -972,7 +968,9 @@ variant typeinfo
variant utility
variant version
vector algorithm
vector array
vector atomic
vector cerrno
vector climits
vector compare
vector concepts
@ -983,8 +981,11 @@ vector cstring
vector initializer_list
vector iosfwd
vector limits
vector locale
vector new
vector stdexcept
vector string
vector string_view
vector tuple
vector type_traits
vector typeinfo

1 algorithm atomic
583 mutex cstdlib
584 mutex cstring
585 mutex ctime
mutex functional
586 mutex initializer_list
587 mutex iosfwd
588 mutex limits
813 string cstdlib
814 string cstring
815 string cwchar
string functional
816 string initializer_list
817 string iosfwd
818 string iterator
824 string type_traits
825 string typeinfo
826 string utility
string vector
827 string version
828 string_view algorithm
829 string_view compare
834 string_view cstdlib
835 string_view cstring
836 string_view cwchar
string_view functional
837 string_view initializer_list
838 string_view iosfwd
839 string_view iterator
968 variant utility
969 variant version
970 vector algorithm
971 vector array
972 vector atomic
973 vector cerrno
974 vector climits
975 vector compare
976 vector concepts
981 vector initializer_list
982 vector iosfwd
983 vector limits
984 vector locale
985 vector new
986 vector stdexcept
987 vector string
988 vector string_view
989 vector tuple
990 vector type_traits
991 vector typeinfo

View File

@ -646,15 +646,21 @@ variant limits
variant new
variant tuple
variant version
vector array
vector cerrno
vector climits
vector compare
vector cstddef
vector cstdint
vector cstdlib
vector cstring
vector initializer_list
vector iosfwd
vector limits
vector locale
vector new
vector stdexcept
vector string
vector string_view
vector tuple
vector version

1 algorithm climits
646 variant new
647 variant tuple
648 variant version
649 vector array
650 vector cerrno
651 vector climits
652 vector compare
653 vector cstddef
654 vector cstdint
655 vector cstdlib
656 vector cstring
657 vector initializer_list
658 vector iosfwd
659 vector limits
660 vector locale
661 vector new
662 vector stdexcept
663 vector string
664 vector string_view
665 vector tuple
666 vector version

View File

@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// UNSUPPORTED: libcpp-has-no-incomplete-format
// <vector>
// template<class T, class charT> requires is-vector-bool-reference<T>
// struct formatter<T, charT>;
// [format.formatter.spec]/4
// If the library provides an explicit or partial specialization of
// formatter<T, charT>, that specialization is enabled and meets the
// Formatter requirements except as noted otherwise.
//
// Tests parts of the BasicFormatter requirements. Like the formattable concept
// it uses the semiregular concept. It test does not use the formattable
// concept since it is the intention the formatter is available without
// including the format header.
// TODO FMT Evaluate what to do with [format.formatter.spec]/2
// [format.formatter.spec]/2
// Each header that declares the template formatter provides the following
// enabled specializations:
// Then there is a list of formatters, but is that really useful?
// Note this should be discussed in LEWG.
#include <concepts>
#include <vector>
#include "test_macros.h"
static_assert(std::semiregular<std::formatter<std::vector<bool>::reference, char>>);
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
static_assert(std::semiregular<std::formatter<std::vector<bool>::reference, wchar_t>>);
#endif