/* char8_t support is implicitly enabled in C++20 and C2X. */
if (flag_char8_t == -1)
flag_char8_t = (cxx_dialect >= cxx20) || flag_isoc2x;
+ cpp_opts->unsigned_utf8char = flag_char8_t ? 1 : cpp_opts->unsigned_char;
if (flag_extern_tls_init)
{
// Test that UTF-8 character literals have type char if -fchar8_t is not enabled.
// { dg-do compile }
-// { dg-options "-std=c++17 -fno-char8_t" }
+// { dg-options "-std=c++17 -fsigned-char -fno-char8_t" }
template<typename T1, typename T2>
struct is_same
{ static const bool value = true; };
static_assert(is_same<decltype(u8'x'), char>::value, "Error");
+
+#if u8'\0' - 1 > 0
+#error "UTF-8 character literals not signed in preprocessor"
+#endif
{ static const bool value = true; };
static_assert(is_same<decltype(u8'x'), char8_t>::value, "Error");
+
+#if u8'\0' - 1 < 0
+#error "UTF-8 character literals not unsigned in preprocessor"
+#endif
/* Multichar constants are of type int and therefore signed. */
if (i > 1)
unsigned_p = 0;
- else if (type == CPP_UTF8CHAR && !CPP_OPTION (pfile, cplusplus))
- unsigned_p = 1;
+ else if (type == CPP_UTF8CHAR)
+ unsigned_p = CPP_OPTION (pfile, unsigned_utf8char);
else
unsigned_p = CPP_OPTION (pfile, unsigned_char);
ints and target wide characters, respectively. */
size_t precision, char_precision, int_precision, wchar_precision;
- /* True means chars (wide chars) are unsigned. */
- bool unsigned_char, unsigned_wchar;
+ /* True means chars (wide chars, UTF-8 chars) are unsigned. */
+ bool unsigned_char, unsigned_wchar, unsigned_utf8char;
/* True if the most significant byte in a word has the lowest
address in memory. */
CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int);
CPP_OPTION (pfile, unsigned_char) = 0;
CPP_OPTION (pfile, unsigned_wchar) = 1;
+ CPP_OPTION (pfile, unsigned_utf8char) = 1;
CPP_OPTION (pfile, bytes_big_endian) = 1; /* does not matter */
/* Default to no charset conversion. */