]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Use empty field in constexpr eval.
authorJason Merrill <jason@redhat.com>
Mon, 25 Jan 2021 22:02:57 +0000 (17:02 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 29 Apr 2021 18:41:45 +0000 (14:41 -0400)
In discussion of PR98463, Jakub noted that cxx_fold_indirect_ref_1 was
bailing out early for empty bases even when we do have fields for them (in
C++17 mode or later).  This corrects that.

gcc/cp/ChangeLog:

* constexpr.c (cxx_fold_indirect_ref_1): Only set *empty_base if we
don't find a field.

gcc/cp/constexpr.c

index fa7eaed945a48d282a7be448ed988fbf1f5395df..9481a5bfd3c21cbd2690b2938a32abb8c58474d9 100644 (file)
@@ -4734,28 +4734,17 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type,
 {
   tree optype = TREE_TYPE (op);
   unsigned HOST_WIDE_INT const_nunits;
-  if (off == 0)
+  if (off == 0 && similar_type_p (optype, type))
+    return op;
+  else if (TREE_CODE (optype) == COMPLEX_TYPE
+          && similar_type_p (type, TREE_TYPE (optype)))
     {
-      if (similar_type_p (optype, type))
-       return op;
-      /* Also handle conversion to an empty base class, which
-        is represented with a NOP_EXPR.  */
       /* *(foo *)&complexfoo => __real__ complexfoo */
-      else if (TREE_CODE (optype) == COMPLEX_TYPE
-              && similar_type_p (type, TREE_TYPE (optype)))
+      if (off == 0)
        return build1_loc (loc, REALPART_EXPR, type, op);
-    }
-  /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */
-  else if (TREE_CODE (optype) == COMPLEX_TYPE
-          && similar_type_p (type, TREE_TYPE (optype))
-          && tree_to_uhwi (TYPE_SIZE_UNIT (type)) == off)
-    return build1_loc (loc, IMAGPART_EXPR, type, op);
-  if (is_empty_class (type)
-      && CLASS_TYPE_P (optype)
-      && DERIVED_FROM_P (type, optype))
-    {
-      *empty_base = true;
-      return op;
+      /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */
+      else if (tree_to_uhwi (TYPE_SIZE_UNIT (type)) == off)
+       return build1_loc (loc, IMAGPART_EXPR, type, op);
     }
   /* ((foo*)&vectorfoo)[x] => BIT_FIELD_REF<vectorfoo,...> */
   else if (VECTOR_TYPE_P (optype)
@@ -4834,6 +4823,15 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type,
                  return ret;
              }
          }
+      /* Also handle conversion to an empty base class, which
+        is represented with a NOP_EXPR.  */
+      if (is_empty_class (type)
+         && CLASS_TYPE_P (optype)
+         && DERIVED_FROM_P (type, optype))
+       {
+         *empty_base = true;
+         return op;
+       }
     }
 
   return NULL_TREE;