aboutsummaryrefslogtreecommitdiff
path: root/libcpp/charset.cc
diff options
context:
space:
mode:
authorTom Honermann <tom@honermann.net>2022-08-02 14:36:02 -0400
committerJoseph Myers <joseph@codesourcery.com>2022-08-08 19:50:40 +0000
commit053876cdbe8057210e6f4da4eec2df58f92ccd4c (patch)
tree4647bf6d6ec1b7d28931ec90daeefea8c528d118 /libcpp/charset.cc
parent703837b2cc8ac03c53ac7cc0fb1327055acaebd2 (diff)
downloadgcc-053876cdbe8057210e6f4da4eec2df58f92ccd4c.zip
gcc-053876cdbe8057210e6f4da4eec2df58f92ccd4c.tar.gz
gcc-053876cdbe8057210e6f4da4eec2df58f92ccd4c.tar.bz2
preprocessor/106426: Treat u8 character literals as unsigned in char8_t modes.
This patch corrects handling of UTF-8 character literals in preprocessing directives so that they are treated as unsigned types in char8_t enabled C++ modes (C++17 with -fchar8_t or C++20 without -fno-char8_t). Previously, UTF-8 character literals were always treated as having the same type as ordinary character literals (signed or unsigned dependent on target or use of the -fsigned-char or -funsigned char options). PR preprocessor/106426 gcc/c-family/ChangeLog: * c-opts.cc (c_common_post_options): Assign cpp_opts->unsigned_utf8char subject to -fchar8_t, -fsigned-char, and/or -funsigned-char. gcc/testsuite/ChangeLog: * g++.dg/ext/char8_t-char-literal-1.C: Check signedness of u8 literals. * g++.dg/ext/char8_t-char-literal-2.C: Check signedness of u8 literals. libcpp/ChangeLog: * charset.cc (narrow_str_to_charconst): Set signedness of CPP_UTF8CHAR literals based on unsigned_utf8char. * include/cpplib.h (cpp_options): Add unsigned_utf8char. * init.cc (cpp_create_reader): Initialize unsigned_utf8char.
Diffstat (limited to 'libcpp/charset.cc')
-rw-r--r--libcpp/charset.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/libcpp/charset.cc b/libcpp/charset.cc
index ca8b7cf..12e3163 100644
--- a/libcpp/charset.cc
+++ b/libcpp/charset.cc
@@ -1960,8 +1960,8 @@ narrow_str_to_charconst (cpp_reader *pfile, cpp_string str,
/* 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);