https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81045
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Somehow GCC is deciding that easyObjects->begin() and end() are dependent types so you need to use the template keyword for the call to cast. That is: auto casted = obj.template cast<T>(); I don't know if GCC is correct here or not.