Templates: better handling of 'X<class Y>' template instantiations. Ticket: #4544