Hi, Here, we were setting the LOOKUP_NONVIRTUAL flag wrongly. Actually, we need to check if the function context is the same than the instance type -- yes that might happen that they be different in presence of using-declarations.
It happens that it was working if the call was invoked through a pointer, that's because we were failing to determine the dynamic type (in resolved_fixed_type_p). On the contrary, it wasn't working if the call was done through a reference because we manage to determine the dynamic_type thanks to a special case in fixed_type_or_null. There is probably room for improvement here, though I'm not sure the C++ front end is the better place to de-virtualize. Tested x84_64-unknown-linux-gnu without regressions. OK to commit ? gcc/testsuite/ChangeLog 2012-08-12 Fabien Chêne <fab...@gcc.gnu.org> PR c++/11750 * g++.dg/inherit/vitual9.C: New. gcc/cp/ChangeLog 2012-08-12 Fabien Chêne <fab...@gcc.gnu.org> PR c++/11750 * call.c (build_new_method_call_1): Check that the instance type and the function context are the same before setting the flag LOOKUP_NONVIRTUAL. -- Fabien
pr11750.patch
Description: Binary data