My previous commit (naively) assumed that a TREE_CODE of RECORD_TYPE or
UNION_TYPE was sufficient for optype to be considered a "class type".
However, this does not account for e.g. template type parameters of
record or union type. This patch corrects to check for CLASS_TYPE_P
before checking for as-base conversion.
PR c++/113031
gcc/cp/ChangeLog:
* constexpr.cc (cxx_fold_indirect_ref_1): Check for CLASS_TYPE
before using CLASSTYPE_AS_BASE.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/pr113031.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
}
/* 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
--- /dev/null
+// PR c++/113031
+// { dg-do compile }
+
+template <typename> struct variant;
+
+template <typename _Types, typename _Tp>
+variant<_Types> __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();
+ }
+ };
+ };
+};