]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Set type on dependent ARROW_EXPR
authorJason Merrill <jason@redhat.com>
Fri, 27 Aug 2021 14:00:49 +0000 (10:00 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 27 Aug 2021 21:37:58 +0000 (17:37 -0400)
Even if the operand of -> has dependent type, if it's a pointer we know
that the result will be the target type of that pointer.  This should avoid
some unnecessary TYPEOF_EXPR when looking up a name after ->.

gcc/cp/ChangeLog:

* typeck2.c (build_x_arrow): Do set TREE_TYPE when operand is
a dependent pointer.

gcc/cp/typeck2.c

index dcfdff2f90553b01ea1835a0e73271636edb4ca7..5e2c23c063cc0f5dee99a41daf6ca49839368d47 100644 (file)
@@ -1913,11 +1913,17 @@ build_x_arrow (location_t loc, tree expr, tsubst_flags_t complain)
 
   if (processing_template_decl)
     {
-      if (type && TYPE_PTR_P (type)
-         && !dependent_scope_p (TREE_TYPE (type)))
+      tree ttype = NULL_TREE;
+      if (type && TYPE_PTR_P (type))
+       ttype = TREE_TYPE (type);
+      if (ttype && !dependent_scope_p (ttype))
        /* Pointer to current instantiation, don't treat as dependent.  */;
       else if (type_dependent_expression_p (expr))
-       return build_min_nt_loc (loc, ARROW_EXPR, expr);
+       {
+         expr = build_min_nt_loc (loc, ARROW_EXPR, expr);
+         TREE_TYPE (expr) = ttype;
+         return expr;
+       }
       expr = build_non_dependent_expr (expr);
     }