------- Comment #8 from jakub at gcc dot gnu dot org 2008-11-04 16:03 ------- Actually, looking at this some more, the problem is just that g has a wrong DECL_ARG_TYPE. When instantiate_class_template is called on B, it instantiates g; class C is returned by lookup_template_class, but not yet a complete type, so it doesn't have TYPE_HAS_INIT_REF set, nor TYPE_HAS_COMPLEX_INIT_REF, nor TREE_ADDRESSABLE. Then tsubst_decl <case PARM_DECL>: if (!DECL_TEMPLATE_PARM_P (r)) DECL_ARG_TYPE (r) = type_passed_as (type); is called, but the RECORD_TYPE C is still incomplete at this point, so type_passed_as, seeing no TREE_ADDRESSABLE being set on type, returns type itself. Afterwards when require_complete_types_for_parms is called on trigger's parameters, instantiate_class_template is called on C and all the above mentioned 3 bits are set. But nothing goes back to fix up DECL_ARG_TYPE, at least not until instantiate_pending_templates eventually calls require_complete_types_for_parms on g's params. But that is already way after trigger has been gimplified. So I believe we need to update DECL_ARG_TYPE (parm) from type_passed_as (TREE_TYPE (parm)) for calls a function is making, but am not sure where would that be best done. In genericization?
-- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36631