aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-11-07 21:24:38 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2019-11-07 21:24:38 +0100
commit2c03d73667df53165834e9bcb5d09243db414ec3 (patch)
tree2b484f05c4147f1d373d5966366fa8899c4c8a74 /libcpp
parent8b4f2b5e0871d32d0f78ce3f3250af71bfb6f65a (diff)
downloadgcc-2c03d73667df53165834e9bcb5d09243db414ec3.zip
gcc-2c03d73667df53165834e9bcb5d09243db414ec3.tar.gz
gcc-2c03d73667df53165834e9bcb5d09243db414ec3.tar.bz2
PR c++/91370 - Implement P1041R4 and P1139R2 - Stronger Unicode reqs
PR c++/91370 - Implement P1041R4 and P1139R2 - Stronger Unicode reqs * charset.c (narrow_str_to_charconst): Add TYPE argument. For CPP_UTF8CHAR diagnose whenever number of chars is > 1, using CPP_DL_ERROR instead of CPP_DL_WARNING. (wide_str_to_charconst): For CPP_CHAR16 or CPP_CHAR32, use CPP_DL_ERROR instead of CPP_DL_WARNING when multiple char16_t or char32_t chars are needed. (cpp_interpret_charconst): Adjust narrow_str_to_charconst caller. * g++.dg/cpp1z/utf8-neg.C: Expect errors rather than -Wmultichar warnings. * g++.dg/ext/utf16-4.C: Expect errors rather than warnings. * g++.dg/ext/utf32-4.C: Likewise. * g++.dg/cpp2a/ucn2.C: New test. From-SVN: r277929
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog11
-rw-r--r--libcpp/charset.c16
2 files changed, 22 insertions, 5 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 8be8438..b57f265 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,14 @@
+2019-11-07 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/91370 - Implement P1041R4 and P1139R2 - Stronger Unicode reqs
+ * charset.c (narrow_str_to_charconst): Add TYPE argument. For
+ CPP_UTF8CHAR diagnose whenever number of chars is > 1, using
+ CPP_DL_ERROR instead of CPP_DL_WARNING.
+ (wide_str_to_charconst): For CPP_CHAR16 or CPP_CHAR32, use
+ CPP_DL_ERROR instead of CPP_DL_WARNING when multiple char16_t
+ or char32_t chars are needed.
+ (cpp_interpret_charconst): Adjust narrow_str_to_charconst caller.
+
2019-11-05 Tim van Deurzen <tim@kompiler.org>
* cpplib.h: Add spaceship operator for C++.
diff --git a/libcpp/charset.c b/libcpp/charset.c
index 39af77a..0b8815a 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -1881,10 +1881,11 @@ cpp_interpret_string_notranslate (cpp_reader *pfile, const cpp_string *from,
/* Subroutine of cpp_interpret_charconst which performs the conversion
to a number, for narrow strings. STR is the string structure returned
by cpp_interpret_string. PCHARS_SEEN and UNSIGNEDP are as for
- cpp_interpret_charconst. */
+ cpp_interpret_charconst. TYPE is the token type. */
static cppchar_t
narrow_str_to_charconst (cpp_reader *pfile, cpp_string str,
- unsigned int *pchars_seen, int *unsignedp)
+ unsigned int *pchars_seen, int *unsignedp,
+ enum cpp_ttype type)
{
size_t width = CPP_OPTION (pfile, char_precision);
size_t max_chars = CPP_OPTION (pfile, int_precision) / width;
@@ -1913,10 +1914,12 @@ narrow_str_to_charconst (cpp_reader *pfile, cpp_string str,
result = c;
}
+ if (type == CPP_UTF8CHAR)
+ max_chars = 1;
if (i > max_chars)
{
i = max_chars;
- cpp_error (pfile, CPP_DL_WARNING,
+ cpp_error (pfile, type == CPP_UTF8CHAR ? CPP_DL_ERROR : CPP_DL_WARNING,
"character constant too long for its type");
}
else if (i > 1 && CPP_OPTION (pfile, warn_multichar))
@@ -1980,7 +1983,9 @@ wide_str_to_charconst (cpp_reader *pfile, cpp_string str,
character exactly fills a wchar_t, so a multi-character wide
character constant is guaranteed to overflow. */
if (str.len > nbwc * 2)
- cpp_error (pfile, CPP_DL_WARNING,
+ cpp_error (pfile, (CPP_OPTION (pfile, cplusplus)
+ && (type == CPP_CHAR16 || type == CPP_CHAR32))
+ ? CPP_DL_ERROR : CPP_DL_WARNING,
"character constant too long for its type");
/* Truncate the constant to its natural width, and simultaneously
@@ -2038,7 +2043,8 @@ cpp_interpret_charconst (cpp_reader *pfile, const cpp_token *token,
result = wide_str_to_charconst (pfile, str, pchars_seen, unsignedp,
token->type);
else
- result = narrow_str_to_charconst (pfile, str, pchars_seen, unsignedp);
+ result = narrow_str_to_charconst (pfile, str, pchars_seen, unsignedp,
+ token->type);
if (str.text != token->val.str.text)
free ((void *)str.text);