https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102002
Bug ID: 102002 Summary: spec requires typename can be dropped when used as template function return type consisting of template parameter which is at global scope Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nickhuang99 at hotmail dot com Target Milestone: --- Spec considers *typename* can be dropped when there is no ambiguous of regarding identifier as type. And example(https://timsong-cpp.github.io/cppwp/temp.res#general-example-5) shows this OK. template<class T> T::R f();//OK, return type of a function declaration at global scope However, all compilers including GCC, clang, MSVC++ complains missing typename because error: need ‘typename’ before ‘T::R’ because ‘T’ is a dependent scope 1 | template<class T> T::R f(); | ^ | typename Here I quote spec(https://timsong-cpp.github.io/cppwp/temp.res#general-4.1): A qualified or unqualified name is said to be in a type-only context if it is the terminal name of a typename-specifier, nested-name-specifier, elaborated-type-specifier, class-or-decltype ... I understand this relaxation of enforcing *typename* is not so critical. Still it is nice to strictly follow spec.