Bug 102002 - spec requires typename can be dropped when used as template function return type consisting of template parameter which is at global scope
Summary: spec requires typename can be dropped when used as template function return t...
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2021-08-20 15:33 UTC by qingzhe huang
Modified: 2021-08-21 00:51 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description qingzhe huang 2021-08-20 15:33:37 UTC
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.
Comment 1 Marek Polacek 2021-08-20 15:54:42 UTC
You need to use -std=c++20.
Comment 2 qingzhe huang 2021-08-21 00:51:15 UTC
Thank you and my apology.