[libcxx-commits] [PATCH] D140819: [libc++][format] Fixes escaping string literals.
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jan 1 08:19:13 PST 2023
Mordante created this revision.
Mordante added reviewers: ldionne, vitaut.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
D140653 <https://reviews.llvm.org/D140653> has the same fix, without the extra tests.
Fixes PR59763
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D140819
Files:
libcxx/include/__format/formatter_string.h
libcxx/test/std/utilities/format/format.tuple/format.functions.tests.h
Index: libcxx/test/std/utilities/format/format.tuple/format.functions.tests.h
===================================================================
--- libcxx/test/std/utilities/format/format.tuple/format.functions.tests.h
+++ libcxx/test/std/utilities/format/format.tuple/format.functions.tests.h
@@ -13,6 +13,7 @@
#include "make_string.h"
+#define CSTR(S) MAKE_CSTRING(CharT, S)
#define STR(S) MAKE_STRING(CharT, S)
#define SV(S) MAKE_STRING_VIEW(CharT, S)
@@ -174,6 +175,8 @@
template <class CharT, class TestFunction, class ExceptionTest>
void test_pair_int_string(TestFunction check, ExceptionTest check_exception) {
test_tuple_or_pair_int_string<CharT>(check, check_exception, std::make_pair(42, SV("hello")));
+ test_tuple_or_pair_int_string<CharT>(check, check_exception, std::make_pair(42, STR("hello")));
+ test_tuple_or_pair_int_string<CharT>(check, check_exception, std::make_pair(42, CSTR("hello")));
}
//
@@ -286,6 +289,8 @@
template <class CharT, class TestFunction, class ExceptionTest>
void test_tuple_int_string(TestFunction check, ExceptionTest check_exception) {
test_tuple_or_pair_int_string<CharT>(check, check_exception, std::make_tuple(42, SV("hello")));
+ test_tuple_or_pair_int_string<CharT>(check, check_exception, std::make_tuple(42, STR("hello")));
+ test_tuple_or_pair_int_string<CharT>(check, check_exception, std::make_tuple(42, CSTR("hello")));
}
//
Index: libcxx/include/__format/formatter_string.h
===================================================================
--- libcxx/include/__format/formatter_string.h
+++ libcxx/include/__format/formatter_string.h
@@ -65,6 +65,12 @@
_LIBCPP_ASSERT(__str, "The basic_format_arg constructor should have "
"prevented an invalid pointer.");
+ __format_spec::__parsed_specifications<_CharT> __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx);
+# if _LIBCPP_STD_VER > 20
+ if (_Base::__parser_.__type_ == __format_spec::__type::__debug)
+ return __formatter::__format_escaped_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs);
+# endif
+
// When using a center or right alignment and the width option the length
// of __str must be known to add the padding upfront. This case is handled
// by the base class by converting the argument to a basic_string_view.
@@ -76,7 +82,6 @@
// now these optimizations aren't implemented. Instead the base class
// handles these options.
// TODO FMT Implement these improvements.
- __format_spec::__parsed_specifications<_CharT> __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx);
if (__specs.__has_width() || __specs.__has_precision())
return __formatter::__write_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140819.485806.patch
Type: text/x-patch
Size: 2805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230101/5a9535f6/attachment.bin>
More information about the libcxx-commits
mailing list