}
template<typename _CharT, typename _Out>
- _Out
+ _GLIBCXX_CONSTEXPR_FORMAT _Out
__write_escaped_ascii(_Out __out,
basic_string_view<_CharT> __str,
_Term_char __term)
{
using _Str_view = basic_string_view<_CharT>;
+ if consteval {
+ // As set of the escaped characters depends on the encoding, for
+ // compile time allow only printable ASCII and standard escapes.
+ constexpr _Str_view __supported(_GLIBCXX_WIDEN(
+ "ABCDEFGHIJKLMNOPQRSTUWXYZ"
+ "abdeefghijklmnopqrstuwzyz"
+ " !#$%&'()*+-./:;<=>?[]^_{|}~"
+ "0123456789" "\t\n\r\\\"\'\0"
+ ), 95);
+ if (__str.find_first_not_of(__supported) != _Str_view::npos)
+#if __has_builtin(__builtin_constexpr_diag)
+ __builtin_constexpr_diag (2, "",
+ "for non-Unicode literal encodings, only"
+ " printable ASCII characters and standard"
+ " escape sequencess can be escaped in constant"
+ " expressions");
+#else
+ __asm__("");
+#endif
+ }
+
auto __first = __str.begin();
auto const __last = __str.end();
while (__first != __last)
VERIFY( res == WIDEN(R"("'")") );
res = fdebug(apos[0]);
VERIFY( res == WIDEN(R"('\'')") );
+
+ // This is not standard escape, but still supported at compile time.
+ const std::basic_string<CharT> null(WIDEN("\0"), 1);
+ res = fdebug(null);
+ VERIFY( res == WIDEN(R"("\u{0}")") );
+ res = fdebug(null[0]);
+ VERIFY( res == WIDEN(R"('\u{0}')") );
}
template<typename CharT>
{
test_basic_escapes<char>();
test_basic_escapes<wchar_t>();
+
+#ifndef UNICODE_ENC
+ // For non-unicode literal encoding debug output only supports
+ // printable ASCII and standard escapes at compile time
+ if (std::is_constant_evaluated())
+ return true;
+#endif
+
test_ascii_escapes<char>();
test_ascii_escapes<wchar_t>();
test_extended_ascii<char>();
return true;
}
-#if defined(__glibcxx_constexpr_format) && defined(UNICODE_ENC)
-// Deboug ouput is supported only for unicode literal encoding
+#ifdef __glibcxx_constexpr_format
static_assert(test_all());
#endif
--- /dev/null
+// { dg-options "-fexec-charset=ISO-8859-1" }
+// { dg-do compile { target c++26 } }
+// { dg-require-effective-target cxx11_abi }
+// { dg-require-iconv "ISO-8859-1" }
+
+#include <format>
+
+constexpr bool
+test_format(std::string_view str)
+{
+ (void)std::format("{:?}", str);
+ return true;
+}
+
+static_assert(test_format("\x10")); // { dg-error "in 'constexpr' expansion of" }
+static_assert(test_format("Åëÿ")); // { dg-error "in 'constexpr' expansion of" }
+
+// { dg-prune-output "for non-Unicode literal encodings, only printable ASCII characters and standard" }
+