Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
This addresses the cp_parser_type_id_1 comment in
<https://gcc.gnu.org/pipermail/gcc-patches/2025-December/704168.html>
asking for simplifying the type_alias_p handling.

gcc/cp/ChangeLog:

        * parser.cc (cp_parser_type_specifier): Adjust comment.
        (cp_parser_type_id_1): Simplify setting of type_alias_p.
        Use nullptr instead of NULL.
---
 gcc/cp/parser.cc | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 393c8b2ec44..d33ce7113f2 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -22263,7 +22263,7 @@ cp_parser_type_specifier (cp_parser* parser,
       /* Fall through.  */
     case RID_TYPENAME:
       /* If we see 'typename [:', this could be a typename-specifier.
-        But if there's no '::' after the '[:x:]' then it is probably
+        But if there's no '::' after the '[:x:]' then it is
         a simple-type-specifier.  */
       if (keyword == RID_TYPENAME
          && cp_parser_nth_token_starts_splice_without_nns_p (parser, 2))
@@ -27647,7 +27647,6 @@ cp_parser_type_id_1 (cp_parser *parser, cp_parser_flags 
flags,
 {
   cp_decl_specifier_seq type_specifier_seq;
   cp_declarator *abstract_declarator;
-  cp_token *next = nullptr;
 
   /* Parse the type-specifier-seq.  */
   cp_parser_type_specifier_seq (parser, flags,
@@ -27657,17 +27656,6 @@ cp_parser_type_id_1 (cp_parser *parser, 
cp_parser_flags flags,
   if (type_location)
     *type_location = type_specifier_seq.locations[ds_type_spec];
 
-  /* If there is just ds_type_spec specified, this could be a type alias.  */
-  if (type_alias_p && is_typedef_decl (type_specifier_seq.type))
-    {
-      int i;
-      for (i = ds_first; i < ds_last; ++i)
-       if (i != ds_type_spec && type_specifier_seq.locations[i])
-         break;
-      if (i == ds_last)
-       next = cp_lexer_peek_token (parser->lexer);
-    }
-
   if (is_template_arg && type_specifier_seq.type
       && TREE_CODE (type_specifier_seq.type) == TEMPLATE_TYPE_PARM
       && CLASS_PLACEHOLDER_TEMPLATE (type_specifier_seq.type))
@@ -27693,12 +27681,19 @@ cp_parser_type_id_1 (cp_parser *parser, 
cp_parser_flags flags,
                            /*static_p=*/false);
   /* Check to see if there really was a declarator.  */
   if (!cp_parser_parse_definitely (parser))
-    abstract_declarator = NULL;
+    abstract_declarator = nullptr;
 
   /* If we found * or & and similar after the type-specifier, it's not
      a type alias.  */
   if (type_alias_p)
-    *type_alias_p = cp_lexer_peek_token (parser->lexer) == next;
+    *type_alias_p = [&] {
+      if (abstract_declarator || !is_typedef_decl (type_specifier_seq.type))
+       return false;
+      for (int i = ds_first; i < ds_last; ++i)
+       if (i != ds_type_spec && type_specifier_seq.locations[i])
+         return false;
+      return true;
+    } ();
 
   bool auto_typeid_ok = false;
   /* DR 625 prohibits use of auto as a template-argument.  We allow 'auto'

base-commit: 2ab314d52bf762059d6c15caf007151381180773
-- 
2.52.0

Reply via email to