On 12/11/19 5:50 PM, Marek Polacek wrote:
On Fri, Nov 22, 2019 at 04:11:53PM -0500, Jason Merrill wrote:
On 11/8/19 4:24 PM, Marek Polacek wrote:

2) [class.cdtor] says that when a dynamic_cast is used in a constructor or
destructor and the operand of the dynamic_cast refers to the object under
construction or destruction, this object is considered to be a most derived
object.

This means that during the 'tor the vtable pointer refers to the type_info
for that class and the offset-to-top is 0.  Can you use that?

I can't seem to: For e.g.

struct C : A, C2 { A *c = dynamic_cast<A*>(static_cast<C2*>(this)); };

the object under construction is C, the call to __dynamic_cast will be
__dynamic_cast (SAVE_EXPR <&((struct C *) this)->D.2119>, &_ZTI2C2, &_ZTI1A, -2)
here, OBJ is f.D.2156.D.2119 and ctx->global->ctor_object is f.D.2156.  So OBJ
refers to the object under construction.

But I don't see C anywhere; CLASSTYPE_TYPEINFO_VAR of OBJTYPE is _ZTI2C2.

Am I looking into the wrong place?

Evaluating build_vfield_ref (obj, objtype) will give you the vtable pointer, in this case &_ZTV1C + 40. And then you can get C from DECL_CONTEXT (_ZTV1C).

Or get_tinfo_decl_dynamic (obj) will give you the type_info.

Jason

Reply via email to