diff options
author | Tom Honermann <tom@honermann.net> | 2019-01-14 19:55:51 +0000 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2019-01-14 14:55:51 -0500 |
commit | 2d91f79dc990f81dcea89a5087cad566238b2456 (patch) | |
tree | ae9137b811a3a0bdada65dbb8a6ed5dba9d24b0e /gcc/cp/parser.c | |
parent | 23db6ced33c245c38c147c31011bbafa392e4328 (diff) | |
download | gcc-2d91f79dc990f81dcea89a5087cad566238b2456.zip gcc-2d91f79dc990f81dcea89a5087cad566238b2456.tar.gz gcc-2d91f79dc990f81dcea89a5087cad566238b2456.tar.bz2 |
Implement P0482R5, char8_t: A type for UTF-8 characters and strings
gcc/cp/
* cvt.c (type_promotes_to): Handle char8_t promotion.
* decl.c (grokdeclarator): Handle invalid type specifier
combinations involving char8_t.
* lex.c (init_reswords): Add char8_t as a reserved word.
* mangle.c (write_builtin_type): Add name mangling for char8_t (Du).
* parser.c (cp_keyword_starts_decl_specifier_p)
(cp_parser_simple_type_specifier): Recognize char8_t as a simple
type specifier.
(cp_parser_string_literal): Use char8_array_type_node for the type
of CPP_UTF8STRING.
(cp_parser_set_decl_spec_type): Tolerate char8_t typedefs in system
headers.
* rtti.c (emit_support_tinfos): type_info support for char8_t.
* tree.c (char_type_p): Recognize char8_t as a character type.
* typeck.c (string_conv_p): Handle conversions of u8 string
literals of char8_t type.
(check_literal_operator_args): Handle UDLs with u8 string literals
of char8_t type.
* typeck2.c (ordinary_char_type_p): New.
(digest_init_r): Disallow initializing a char array with a u8 string
literal.
gcc/c-family/
* c-common.c (c_common_reswords): Add char8_t.
(fix_string_type): Use char8_t for the type of u8 string literals.
(c_common_get_alias_set): char8_t doesn't alias.
(c_common_nodes_and_builtins): Define char8_t as a builtin type in
C++.
(c_stddef_cpp_builtins): Add __CHAR8_TYPE__.
(keyword_begins_type_specifier): Add RID_CHAR8.
* c-common.h (rid): Add RID_CHAR8.
(c_tree_index): Add CTI_CHAR8_TYPE and CTI_CHAR8_ARRAY_TYPE.
Define D_CXX_CHAR8_T and D_CXX_CHAR8_T_FLAGS.
Define char8_type_node and char8_array_type_node.
* c-cppbuiltin.c (cpp_atomic_builtins): Predefine
__GCC_ATOMIC_CHAR8_T_LOCK_FREE.
(c_cpp_builtins): Predefine __cpp_char8_t.
* c-lex.c (lex_string): Use char8_array_type_node as the type of
CPP_UTF8STRING.
(lex_charconst): Use char8_type_node as the type of CPP_UTF8CHAR.
* c-opts.c: If not otherwise specified, enable -fchar8_t when
targeting C++2a.
* c.opt: Add the -fchar8_t command line option.
libiberty/
* cp-demangle.c (cplus_demangle_builtin_types)
(cplus_demangle_type): Add name demangling for char8_t (Du).
* cp-demangle.h: Increase D_BUILTIN_TYPE_COUNT to accommodate the
new char8_t type.
From-SVN: r267923
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index be669f2..7d7b029 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -948,6 +948,7 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) case RID_TYPENAME: /* Simple type specifiers. */ case RID_CHAR: + case RID_CHAR8: case RID_CHAR16: case RID_CHAR32: case RID_WCHAR: @@ -4235,9 +4236,14 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok, { default: case CPP_STRING: - case CPP_UTF8STRING: TREE_TYPE (value) = char_array_type_node; break; + case CPP_UTF8STRING: + if (flag_char8_t) + TREE_TYPE (value) = char8_array_type_node; + else + TREE_TYPE (value) = char_array_type_node; + break; case CPP_STRING16: TREE_TYPE (value) = char16_array_type_node; break; @@ -17504,6 +17510,9 @@ cp_parser_simple_type_specifier (cp_parser* parser, decl_specs->explicit_char_p = true; type = char_type_node; break; + case RID_CHAR8: + type = char8_type_node; + break; case RID_CHAR16: type = char16_type_node; break; @@ -28919,14 +28928,15 @@ cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs, { decl_specs->any_specifiers_p = true; - /* If the user tries to redeclare bool, char16_t, char32_t, or wchar_t - (with, for example, in "typedef int wchar_t;") we remember that + /* If the user tries to redeclare bool, char8_t, char16_t, char32_t, or + wchar_t (with, for example, in "typedef int wchar_t;") we remember that this is what happened. In system headers, we ignore these declarations so that G++ can work with system headers that are not C++-safe. */ if (decl_spec_seq_has_spec_p (decl_specs, ds_typedef) && !type_definition_p && (type_spec == boolean_type_node + || type_spec == char8_type_node || type_spec == char16_type_node || type_spec == char32_type_node || type_spec == wchar_type_node) |