https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55576
--- Comment #15 from Jason Merrill <jason at gcc dot gnu.org> --- Looking at the standard again, I notice When the name of a member template specialization appears after . or -> in a postfix-expression or after a nested-name-specifier in a qualified-id, and the object expression of the postfix-expression is type-dependent or the nested-name-specifier in the qualified-id refers to a dependent type, but the name is not a member of the current instantiation (14.6.2.1), the member template name must be prefixed by the keyword template. This suggests that the 'template' keyword specifies that the following name is a *member* template, and that we shouldn't look in the current scope at all. It seems like the main change needed is passing template_keyword_p into cp_parser_nested_name_specifier_opt.