On 10/20/23 09:53, Ken Matsui wrote:
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 {};.
+/* Peeks the corresponding built-in trait if a given token is
a built-in trait. Otherwise, returns nullptr. */
static const cp_trait *
+cp_lexer_peek_trait (cp_lexer *lexer, const cp_token *token1)
Passing in both the lexer and the peeked token seems awkward, let's just
pass in the lexer. Looking up the peeked token again is fast.
{
+ if (token1->type == CPP_NAME && IDENTIFIER_TRAIT_P (token1->u.value))
+ {
+ const cp_trait &trait = cp_traits[IDENTIFIER_CP_INDEX (token1->u.value)];
+ const bool is_pack_element = (trait.kind == CPTK_TYPE_PACK_ELEMENT);
+
+ /* Check if the subsequent token is a `<' token to
+ __type_pack_element or is a `(' token to everything else. */
git complains about indentation with spaces instead of a tab on this line.
Jason