https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113031

--- Comment #2 from Nathaniel Shead <nathanieloshead at gmail dot com> ---
Reduced to:


template <typename> class variant;

template <typename _Types, typename _Tp>
auto __variant_cast(_Tp __rhs) { return static_cast<variant<_Types>&&>(__rhs);
}

template <typename _Types>
struct _Move_assign_base : _Types {
  void operator=(_Move_assign_base __rhs) { __variant_cast<_Types>(__rhs); }
};

template <typename _Types>
struct variant : _Move_assign_base<_Types> {
  void emplace() {
    variant __tmp;
    *this = __tmp;
  }
};

struct _Undefined_class {
  struct _Nocopy_types {
    void (_Undefined_class::*_M_member_pointer)();
  };
  struct function : _Nocopy_types {
    struct optional {
      void test03() {
        variant<function> v;
        v.emplace();
      }
    };
  };
};


The following patch seems to fix the immediate problem (but not yet fully
regtested):

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index e1b2d27fc36..051f73fb73f 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -5709,7 +5709,8 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx,
location_t loc, tree type,
          }

       /* Handle conversion to "as base" type.  */
-      if (CLASSTYPE_AS_BASE (optype) == type)
+      if (CLASS_TYPE_P (optype)
+         && CLASSTYPE_AS_BASE (optype) == type)
        return op;

       /* Handle conversion to an empty base class, which is represented with a

Reply via email to