summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2019-09-26 21:43:51 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2019-09-26 21:43:51 +0000
commit0900e29cdbc533fecf2a311447bbde17f101bbd6 (patch)
tree99d96116ec1656e4b86de00444ee3569f3d46ba7 /libcpp
parentd7326aaf20871a81feb39673d78922c1bc83efec (diff)
charset.c (UCS_LIMIT): New macro.
* charset.c (UCS_LIMIT): New macro. (ucn_valid_in_identifier): Use it instead of a hardcoded constant. (_cpp_valid_ucn): Issue a pedantic warning for UCNs larger than UCS_LIMIT outside of identifiers in C and in C++2a or later. From-SVN: r276167
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog7
-rw-r--r--libcpp/charset.c15
2 files changed, 21 insertions, 1 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 0c851952b55..1ca622df6fd 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2019-09-26 Eric Botcazou <ebotcazou@adacore.com>
+
+ * charset.c (UCS_LIMIT): New macro.
+ (ucn_valid_in_identifier): Use it instead of a hardcoded constant.
+ (_cpp_valid_ucn): Issue a pedantic warning for UCNs larger than
+ UCS_LIMIT outside of identifiers in C and in C++2a or later.
+
2019-09-19 Lewis Hyatt <lhyatt@gmail.com>
PR c/67224
diff --git a/libcpp/charset.c b/libcpp/charset.c
index 10286219bd6..39af77a554a 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -901,6 +901,9 @@ struct ucnrange {
};
#include "ucnid.h"
+/* ISO 10646 defines the UCS codespace as the range 0-0x10FFFF inclusive. */
+#define UCS_LIMIT 0x10FFFF
+
/* Returns 1 if C is valid in an identifier, 2 if C is valid except at
the start of an identifier, and 0 if C is not valid in an
identifier. We assume C has already gone through the checks of
@@ -915,7 +918,7 @@ ucn_valid_in_identifier (cpp_reader *pfile, cppchar_t c,
int mn, mx, md;
unsigned short valid_flags, invalid_start_flags;
- if (c > 0x10FFFF)
+ if (c > UCS_LIMIT)
return 0;
mn = 0;
@@ -1016,6 +1019,10 @@ ucn_valid_in_identifier (cpp_reader *pfile, cppchar_t c,
whose short identifier is less than 00A0 other than 0024 ($), 0040 (@),
or 0060 (`), nor one in the range D800 through DFFF inclusive.
+ If the hexadecimal value is larger than the upper bound of the UCS
+ codespace specified in ISO/IEC 10646, a pedantic warning is issued
+ in all versions of C and in the C++2a or later versions of C++.
+
*PSTR must be preceded by "\u" or "\U"; it is assumed that the
buffer end is delimited by a non-hex digit. Returns false if the
UCN has not been consumed, true otherwise.
@@ -1135,6 +1142,12 @@ _cpp_valid_ucn (cpp_reader *pfile, const uchar **pstr,
"universal character %.*s is not valid at the start of an identifier",
(int) (str - base), base);
}
+ else if (result > UCS_LIMIT
+ && (!CPP_OPTION (pfile, cplusplus)
+ || CPP_OPTION (pfile, lang) > CLK_CXX17))
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "%.*s is outside the UCS codespace",
+ (int) (str - base), base);
*cp = result;
return true;