While working on Clang, I hit an assertion I don't understand. CodeGen wants to generate this expression:
#20 0x00000001001f9f30 in (anonymous namespace)::AggExprEmitter::VisitCXXConstructExpr (this=0x7fff5fbfd050, E=0x106841540) at clang/lib/CodeGen/CGExprAgg.cpp:552
552 CGF.EmitCXXConstructExpr(E, Slot);
(gdb) call E->dump()
(CXXConstructExpr 0x106841540 'struct B''void (struct B &&)'
(MaterializeTemporaryExpr 0x106841410 'struct B' xvalue
(ImplicitCastExpr 0x1068413f8 'struct B' <LValueToRValue>
(ImplicitCastExpr 0x1068413d8 'struct B' lvalue <UncheckedDerivedToBase (B)>
(DeclRefExpr 0x1068413b0 'struct S' lvalue ParmVar 0x1068410b0 '' 'struct S &&')))))
Note the two nested implicit casts. This eventually reaches AggExprEmitter::VisitCastExpr(CastExpr *E) for the derived-to-base cast, which asserts.
1) Why does it reach the assertion? (I think it's because of the MaterializeTemporaryExpr)
2) How do I avoid that?
I'll gladly explain in greater detail.