The following code should be optimizated out on the tree level but is not because we have a cast involved when calling the deconstuctor. int t; struct base { int i; ~base(){t = i;}}; struct vector : public base { vector(){ i = 2; }}; int f() { vector v; return t;} extern "C" void abort (); int main(void) { t = 2; if (f() != 2) link_error (); if (t!= 2) link_error (); return 0; } This might be the case for PR 19786 but I don't know for sure.
Confirmed, This seems stupid the front-end is doing this as casts get in the way of optimizations now.
The bug is in convert_to_base_statically.
Note this was fixed at the tree level by: 2007-04-08 Jan Hubicka <jh@suse.cz> * tree.h (maybe_fold_offset_to_component_ref): Declare. * tree-ssa-ccp.c (maybe_fold_offset_to_component_ref): Export. * fold-const.c (fold_unary): Use it. But The C++ front-end should not produce this to begin with.
Andrew, any idea about the current status of this? Note that maybe_fold_offset_to_component_ref doesn't exist anymore
This is not needed any more due to MEM_REF.