[libcxx-commits] [libcxx] f68a536 - [libc++][format] Addresses LWG3839.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Mar 7 10:20:24 PST 2023
Author: Mark de Wever
Date: 2023-03-07T19:20:19+01:00
New Revision: f68a536a6785e63f3dd91e505a01264dea9c310b
URL: https://github.com/llvm/llvm-project/commit/f68a536a6785e63f3dd91e505a01264dea9c310b
DIFF: https://github.com/llvm/llvm-project/commit/f68a536a6785e63f3dd91e505a01264dea9c310b.diff
LOG: [libc++][format] Addresses LWG3839.
LWG3839 range_formatter's set_separator, set_brackets, and
underlying functions should be noexcept
Adds tests for:
template<ranges::input_range R, class charT>
struct range-default-formatter<range_format::sequence, R, charT>
These were missing, the format functions tests for the sequences
are already present.
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D144286
Added:
libcxx/test/std/utilities/format/format.range/format.range.fmtdef/format.pass.cpp
libcxx/test/std/utilities/format/format.range/format.range.fmtdef/parse.pass.cpp
libcxx/test/std/utilities/format/format.range/format.range.fmtdef/set_brackets.pass.cpp
libcxx/test/std/utilities/format/format.range/format.range.fmtdef/set_separator.pass.cpp
Modified:
libcxx/docs/Status/Cxx2bIssues.csv
libcxx/include/__format/formatter_tuple.h
libcxx/include/__format/range_default_formatter.h
libcxx/include/__format/range_formatter.h
libcxx/test/std/utilities/format/format.range/format.range.formatter/set_brackets.pass.cpp
libcxx/test/std/utilities/format/format.range/format.range.formatter/set_separator.pass.cpp
libcxx/test/std/utilities/format/format.range/format.range.formatter/underlying.pass.cpp
libcxx/test/std/utilities/format/format.tuple/set_brackets.pass.cpp
libcxx/test/std/utilities/format/format.tuple/set_separator.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv
index 1bdd4bf1a857e..250508b40278c 100644
--- a/libcxx/docs/Status/Cxx2bIssues.csv
+++ b/libcxx/docs/Status/Cxx2bIssues.csv
@@ -264,7 +264,7 @@
"`3819 <https://wg21.link/LWG3819>`__","``reference_meows_from_temporary`` should not use ``is_meowible``","February 2023","","",""
"`3821 <https://wg21.link/LWG3821>`__","``uses_allocator_construction_args`` should have overload for ``pair-like``","February 2023","","",""
"`3834 <https://wg21.link/LWG3834>`__","Missing ``constexpr`` for ``std::intmax_t`` math functions in ``<cinttypes>``","February 2023","","",""
-"`3839 <https://wg21.link/LWG3839>`__","``range_formatter``'s ``set_separator``, ``set_brackets``, and ``underlying`` functions should be ``noexcept``","February 2023","","","|format|"
+"`3839 <https://wg21.link/LWG3839>`__","``range_formatter``'s ``set_separator``, ``set_brackets``, and ``underlying`` functions should be ``noexcept``","February 2023","|Complete|","17.0","|format|"
"`3841 <https://wg21.link/LWG3841>`__","``<version>`` should not be ""all freestanding""","February 2023","","",""
"`3842 <https://wg21.link/LWG3842>`__","Unclear wording for ``precision`` in ``chrono-format-spec``","February 2023","","","|format|"
"`3848 <https://wg21.link/LWG3848>`__","``adjacent_view``, ``adjacent_transform_view`` and ``slide_view`` missing ``base`` accessor","February 2023","","","|ranges|"
diff --git a/libcxx/include/__format/formatter_tuple.h b/libcxx/include/__format/formatter_tuple.h
index e1bfd7c5e11c3..d1874ddecb723 100644
--- a/libcxx/include/__format/formatter_tuple.h
+++ b/libcxx/include/__format/formatter_tuple.h
@@ -40,11 +40,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <__fmt_char_type _CharT, class _Tuple, formattable<_CharT>... _Args>
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __formatter_tuple {
- _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) {
+ _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) noexcept {
__separator_ = __separator;
}
_LIBCPP_HIDE_FROM_ABI constexpr void
- set_brackets(basic_string_view<_CharT> __opening_bracket, basic_string_view<_CharT> __closing_bracket) {
+ set_brackets(basic_string_view<_CharT> __opening_bracket, basic_string_view<_CharT> __closing_bracket) noexcept {
__opening_bracket_ = __opening_bracket;
__closing_bracket_ = __closing_bracket;
}
diff --git a/libcxx/include/__format/range_default_formatter.h b/libcxx/include/__format/range_default_formatter.h
index 136ff063d0697..7fdb254de3b88 100644
--- a/libcxx/include/__format/range_default_formatter.h
+++ b/libcxx/include/__format/range_default_formatter.h
@@ -95,11 +95,11 @@ struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT __range_default_formatte
range_formatter<remove_cvref_t<ranges::range_reference_t<__maybe_const_r>>, _CharT> __underlying_;
public:
- _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) {
+ _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) noexcept {
__underlying_.set_separator(__separator);
}
_LIBCPP_HIDE_FROM_ABI constexpr void
- set_brackets(basic_string_view<_CharT> __opening_bracket, basic_string_view<_CharT> __closing_bracket) {
+ set_brackets(basic_string_view<_CharT> __opening_bracket, basic_string_view<_CharT> __closing_bracket) noexcept {
__underlying_.set_brackets(__opening_bracket, __closing_bracket);
}
diff --git a/libcxx/include/__format/range_formatter.h b/libcxx/include/__format/range_formatter.h
index aac379536219c..f60151029c9c3 100644
--- a/libcxx/include/__format/range_formatter.h
+++ b/libcxx/include/__format/range_formatter.h
@@ -41,17 +41,17 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _CharT = char>
requires same_as<remove_cvref_t<_Tp>, _Tp> && formattable<_Tp, _CharT>
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT range_formatter {
- _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) {
+ _LIBCPP_HIDE_FROM_ABI constexpr void set_separator(basic_string_view<_CharT> __separator) noexcept {
__separator_ = __separator;
}
_LIBCPP_HIDE_FROM_ABI constexpr void
- set_brackets(basic_string_view<_CharT> __opening_bracket, basic_string_view<_CharT> __closing_bracket) {
+ set_brackets(basic_string_view<_CharT> __opening_bracket, basic_string_view<_CharT> __closing_bracket) noexcept {
__opening_bracket_ = __opening_bracket;
__closing_bracket_ = __closing_bracket;
}
- _LIBCPP_HIDE_FROM_ABI constexpr formatter<_Tp, _CharT>& underlying() { return __underlying_; }
- _LIBCPP_HIDE_FROM_ABI constexpr const formatter<_Tp, _CharT>& underlying() const { return __underlying_; }
+ _LIBCPP_HIDE_FROM_ABI constexpr formatter<_Tp, _CharT>& underlying() noexcept { return __underlying_; }
+ _LIBCPP_HIDE_FROM_ABI constexpr const formatter<_Tp, _CharT>& underlying() const noexcept { return __underlying_; }
template <class _ParseContext>
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __parse_ctx) {
diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/format.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/format.pass.cpp
new file mode 100644
index 0000000000000..31b7e5658b125
--- /dev/null
+++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/format.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+// 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
+
+// TODO FMT Fix this test using GCC, it currently times out.
+// UNSUPPORTED: gcc-12
+
+// This test requires the dylib support introduced in D92214.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{.+}}
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx11.{{.+}}
+
+// <format>
+
+// template<ranges::input_range R, class charT>
+// struct range-default-formatter<range_format::sequence, R, charT>
+
+// template<class FormatContext>
+// typename FormatContext::iterator
+// format(maybe-const-r& elems, FormatContext& ctx) const;
+
+#include <array>
+#include <cassert>
+#include <concepts>
+#include <format>
+#include <iterator>
+
+#include "test_format_context.h"
+#include "test_macros.h"
+#include "make_string.h"
+
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class StringViewT>
+void test_format(StringViewT expected, std::array<int, 2> arg) {
+ using CharT = typename StringViewT::value_type;
+ using String = std::basic_string<CharT>;
+ using OutIt = std::back_insert_iterator<String>;
+ using FormatCtxT = std::basic_format_context<OutIt, CharT>;
+
+ std::formatter<std::array<int, 2>, CharT> formatter;
+
+ String result;
+ OutIt out = std::back_inserter(result);
+ FormatCtxT format_ctx = test_format_context_create<OutIt, CharT>(out, std::make_format_args<FormatCtxT>(arg));
+ formatter.format(arg, format_ctx);
+ assert(result == expected);
+}
+
+template <class CharT>
+void test_fmt() {
+ test_format(SV("[1, 42]"), std::array<int, 2>{{1, 42}});
+ test_format(SV("[0, 99]"), std::array<int, 2>{{0, 99}});
+}
+
+void test() {
+ test_fmt<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_fmt<wchar_t>();
+#endif
+}
+
+int main(int, char**) {
+ test();
+
+ return 0;
+}
diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/parse.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/parse.pass.cpp
new file mode 100644
index 0000000000000..a7a160989b336
--- /dev/null
+++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/parse.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+// 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
+
+// TODO FMT Fix this test using GCC, it currently times out.
+// UNSUPPORTED: gcc-12
+
+// This test requires the dylib support introduced in D92214.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{.+}}
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx11.{{.+}}
+
+// <format>
+
+// template<ranges::input_range R, class charT>
+// struct range-default-formatter<range_format::sequence, R, charT>
+
+// template<class ParseContext>
+// constexpr typename ParseContext::iterator
+// parse(ParseContext& ctx);
+
+#include <array>
+#include <cassert>
+#include <concepts>
+#include <format>
+
+#include "test_format_context.h"
+#include "test_macros.h"
+#include "make_string.h"
+
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class StringViewT>
+constexpr void test_parse(StringViewT fmt) {
+ using CharT = typename StringViewT::value_type;
+ auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
+ std::formatter<std::array<int, 2>, CharT> formatter;
+ static_assert(std::semiregular<decltype(formatter)>);
+
+ std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
+ assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}'));
+}
+
+template <class CharT>
+constexpr void test_fmt() {
+ test_parse(SV(""));
+ test_parse(SV(":5"));
+
+ test_parse(SV("}"));
+ test_parse(SV(":5}"));
+}
+
+constexpr bool test() {
+ test_fmt<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_fmt<wchar_t>();
+#endif
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+ static_assert(test());
+
+ return 0;
+}
diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/set_brackets.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/set_brackets.pass.cpp
new file mode 100644
index 0000000000000..6405b5ec22e51
--- /dev/null
+++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/set_brackets.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+// 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
+
+// TODO FMT Fix this test using GCC, it currently times out.
+// UNSUPPORTED: gcc-12
+
+// This test requires the dylib support introduced in D92214.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{.+}}
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx11.{{.+}}
+
+// <format>
+
+// template<ranges::input_range R, class charT>
+// struct range-default-formatter<range_format::sequence, R, charT>
+
+// constexpr void constexpr void set_brackets(basic_string_view<charT> opening,
+// basic_string_view<charT> closing) noexcept;
+
+#include <format>
+#include <cassert>
+#include <iterator>
+#include <type_traits>
+#include <vector>
+
+#include "make_string.h"
+#include "test_format_context.h"
+
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+constexpr void test_setter() {
+ std::formatter<std::vector<int>, CharT> formatter;
+ formatter.set_brackets(SV("open"), SV("close"));
+ // Note the SV macro may throw, so can't use it.
+ static_assert(noexcept(formatter.set_brackets(std::basic_string_view<CharT>{}, std::basic_string_view<CharT>{})));
+
+ // Note there is no direct way to validate this function modified the object.
+ if (!std::is_constant_evaluated()) {
+ using String = std::basic_string<CharT>;
+ using OutIt = std::back_insert_iterator<String>;
+ using FormatCtxT = std::basic_format_context<OutIt, CharT>;
+
+ String result;
+ OutIt out = std::back_inserter(result);
+ FormatCtxT format_ctx = test_format_context_create<OutIt, CharT>(out, std::make_format_args<FormatCtxT>());
+ formatter.format(std::vector<int>{0, 42, 99}, format_ctx);
+ assert(result == SV("open0, 42, 99close"));
+ }
+}
+
+constexpr bool test() {
+ test_setter<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_setter<wchar_t>();
+#endif
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+ static_assert(test());
+
+ return 0;
+}
diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/set_separator.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/set_separator.pass.cpp
new file mode 100644
index 0000000000000..21cee612bb2b0
--- /dev/null
+++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtdef/set_separator.pass.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+// 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
+
+// TODO FMT Fix this test using GCC, it currently times out.
+// UNSUPPORTED: gcc-12
+
+// This test requires the dylib support introduced in D92214.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{.+}}
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx11.{{.+}}
+
+// <format>
+
+// template<ranges::input_range R, class charT>
+// struct range-default-formatter<range_format::sequence, R, charT>
+
+// constexpr void set_separator(basic_string_view<charT> sep) noexcept;
+
+#include <format>
+#include <cassert>
+#include <iterator>
+#include <type_traits>
+#include <vector>
+
+#include "make_string.h"
+#include "test_format_context.h"
+
+#define SV(S) MAKE_STRING_VIEW(CharT, S)
+
+template <class CharT>
+constexpr void test_setter() {
+ std::formatter<std::vector<int>, CharT> formatter;
+ formatter.set_separator(SV("sep"));
+ // Note the SV macro may throw, so can't use it.
+ static_assert(noexcept(formatter.set_separator(std::basic_string_view<CharT>{})));
+
+ // Note there is no direct way to validate this function modified the object.
+ if (!std::is_constant_evaluated()) {
+ using String = std::basic_string<CharT>;
+ using OutIt = std::back_insert_iterator<String>;
+ using FormatCtxT = std::basic_format_context<OutIt, CharT>;
+
+ String result;
+ OutIt out = std::back_inserter(result);
+ FormatCtxT format_ctx = test_format_context_create<OutIt, CharT>(out, std::make_format_args<FormatCtxT>());
+ formatter.format(std::vector<int>{0, 42, 99}, format_ctx);
+ assert(result == SV("[0sep42sep99]"));
+ }
+}
+
+constexpr bool test() {
+ test_setter<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test_setter<wchar_t>();
+#endif
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+ static_assert(test());
+
+ return 0;
+}
diff --git a/libcxx/test/std/utilities/format/format.range/format.range.formatter/set_brackets.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.formatter/set_brackets.pass.cpp
index 6a8989c583f5e..c399a81f2a041 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.formatter/set_brackets.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.range/format.range.formatter/set_brackets.pass.cpp
@@ -22,7 +22,7 @@
// class range_formatter
// constexpr void constexpr void set_brackets(basic_string_view<charT> opening,
-// basic_string_view<charT> closing);
+// basic_string_view<charT> closing) noexcept;
// Note this tests the basics of this function. It's tested in more detail in
// the format functions test.
@@ -42,6 +42,8 @@ template <class CharT>
constexpr void test_setter() {
std::range_formatter<int, CharT> formatter;
formatter.set_brackets(SV("open"), SV("close"));
+ // Note the SV macro may throw, so can't use it.
+ static_assert(noexcept(formatter.set_brackets(std::basic_string_view<CharT>{}, std::basic_string_view<CharT>{})));
// Note there is no direct way to validate this function modified the object.
if (!std::is_constant_evaluated()) {
diff --git a/libcxx/test/std/utilities/format/format.range/format.range.formatter/set_separator.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.formatter/set_separator.pass.cpp
index e95f65edfbd4d..192ddcd16c44a 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.formatter/set_separator.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.range/format.range.formatter/set_separator.pass.cpp
@@ -21,7 +21,7 @@
// requires same_as<remove_cvref_t<T>, T> && formattable<T, charT>
// class range_formatter
-// constexpr void set_separator(basic_string_view<charT> sep);
+// constexpr void set_separator(basic_string_view<charT> sep) noexcept;
// Note this tests the basics of this function. It's tested in more detail in
// the format functions test.
@@ -41,6 +41,8 @@ template <class CharT>
constexpr void test_setter() {
std::range_formatter<int, CharT> formatter;
formatter.set_separator(SV("sep"));
+ // Note the SV macro may throw, so can't use it.
+ static_assert(noexcept(formatter.set_separator(std::basic_string_view<CharT>{})));
// Note there is no direct way to validate this function modified the object.
if (!std::is_constant_evaluated()) {
diff --git a/libcxx/test/std/utilities/format/format.range/format.range.formatter/underlying.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.formatter/underlying.pass.cpp
index 7d819d4ec6c37..10a330f0baf1e 100644
--- a/libcxx/test/std/utilities/format/format.range/format.range.formatter/underlying.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.range/format.range.formatter/underlying.pass.cpp
@@ -21,8 +21,8 @@
// requires same_as<remove_cvref_t<T>, T> && formattable<T, charT>
// class range_formatter
-// constexpr formatter<T, charT>& underlying();
-// constexpr const formatter<T, charT>& underlying() const;
+// constexpr formatter<T, charT>& underlying() noexcept;
+// constexpr const formatter<T, charT>& underlying() const noexcept;
#include <concepts>
#include <format>
@@ -34,10 +34,12 @@ constexpr void test_underlying() {
{
std::range_formatter<int, CharT> formatter;
[[maybe_unused]] std::same_as<std::formatter<int, CharT>&> decltype(auto) underlying = formatter.underlying();
+ static_assert(noexcept(formatter.underlying()));
}
{
const std::range_formatter<int, CharT> formatter;
[[maybe_unused]] std::same_as<const std::formatter<int, CharT>&> decltype(auto) underlying = formatter.underlying();
+ static_assert(noexcept(formatter.underlying()));
}
}
diff --git a/libcxx/test/std/utilities/format/format.tuple/set_brackets.pass.cpp b/libcxx/test/std/utilities/format/format.tuple/set_brackets.pass.cpp
index 86c98455d0a8b..74af4f32fcf1d 100644
--- a/libcxx/test/std/utilities/format/format.tuple/set_brackets.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.tuple/set_brackets.pass.cpp
@@ -21,7 +21,7 @@
// struct formatter<pair-or-tuple<Ts...>, charT>
// constexpr void constexpr void set_brackets(basic_string_view<charT> opening,
-// basic_string_view<charT> closing);
+// basic_string_view<charT> closing) noexcept;
// Note this tests the basics of this function. It's tested in more detail in
// the format functions tests.
@@ -38,6 +38,8 @@ template <class CharT, class Arg>
constexpr void test() {
std::formatter<Arg, CharT> formatter;
formatter.set_brackets(SV("open"), SV("close"));
+ // Note the SV macro may throw, so can't use it.
+ static_assert(noexcept(formatter.set_brackets(std::basic_string_view<CharT>{}, std::basic_string_view<CharT>{})));
// Note there is no direct way to validate this function modified the object.
}
diff --git a/libcxx/test/std/utilities/format/format.tuple/set_separator.pass.cpp b/libcxx/test/std/utilities/format/format.tuple/set_separator.pass.cpp
index fd2c827fe8f47..0258ae215ed22 100644
--- a/libcxx/test/std/utilities/format/format.tuple/set_separator.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.tuple/set_separator.pass.cpp
@@ -21,7 +21,7 @@
// template<class charT, formattable<charT>... Ts>
// struct formatter<pair-or-tuple<Ts...>, charT>
-// constexpr void set_separator(basic_string_view<charT> sep);
+// constexpr void set_separator(basic_string_view<charT> sep) noexcept;
// Note this tests the basics of this function. It's tested in more detail in
// the format functions tests.
@@ -38,6 +38,8 @@ template <class CharT, class Arg>
constexpr void test() {
std::formatter<Arg, CharT> formatter;
formatter.set_separator(SV("sep"));
+ // Note the SV macro may throw, so can't use it.
+ static_assert(noexcept(formatter.set_separator(std::basic_string_view<CharT>{})));
// Note there is no direct way to validate this function modified the object.
}
More information about the libcxx-commits
mailing list