c++: Accept the use of built-in trait identifiers
commitdf3559d951ba6572e254a1bd1ef9a34b6e543325
authorKen Matsui <kmatsui@gcc.gnu.org>
Thu, 7 Dec 2023 05:32:58 +0000 (6 21:32 -0800)
committerJason Merrill <jason@redhat.com>
Sun, 10 Dec 2023 18:11:22 +0000 (10 13:11 -0500)
treeefe4339cbc3111b99897841555ad756724f2cc6c
parent400cd0c26cf86fe75b0e4d42f9976b3125bcfd43
c++: Accept the use of built-in trait identifiers

This patch accepts the use of built-in trait identifiers when they are
actually not used as traits.  Specifically, we check if the subsequent
token is '(' for ordinary built-in traits or is '<' only for the special
__type_pack_element built-in trait.  If those identifiers are used
differently, the parser treats them as normal identifiers.  This allows
us to accept code like: struct __is_pointer {};.

gcc/cp/ChangeLog:

* parser.cc (cp_lexer_lookup_trait): Rename to ...
(cp_lexer_peek_trait): ... this.  Handle a subsequent token for
the corresponding built-in trait.
(cp_lexer_lookup_trait_expr): Rename to ...
(cp_lexer_peek_trait_expr): ... this.
(cp_lexer_lookup_trait_type): Rename to ...
(cp_lexer_peek_trait_type): ... this.
(cp_lexer_next_token_is_decl_specifier_keyword): Call
cp_lexer_peek_trait_type.
(cp_parser_simple_type_specifier): Likewise.
(cp_parser_primary_expression): Call cp_lexer_peek_trait_expr.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
gcc/cp/parser.cc