0

The following code example doesn't compile with Clang 15, in contrast to GCC 12.2 and MSVC 19.33. Shouldn't it be okay to omit typename here due to its relaxed usage in C++20?

template<typename T>    
struct t {
    using v = T::type;
};

The error message produced by Clang:

<source>:3:15: error: missing 'typename' prior to dependent type name 'T::type'
    using v = T::type;
              ^~~~~~~
              typename

From what I can gather on cppreference, the keyword typename can be omitted in contexts where only a type is expected and this also seems to apply to a dependent name in an alias declaration.

In some contexts, only type names can validly appear. In these contexts, a dependent qualified name is assumed to name a type and no typename is required:

...

• A qualified name that appears in type-id, where the smallest enclosing type-id is:
    • the type in a new expression that does not parenthesize its type;
    • the type-id in an alias declaration;
    • a trailing return type,
    • a default argument of a type template parameter, or
    • the type-id of a static_cast, dynamic_cast, const_cast, or reinterpret_cast.

303
  • 2,417
  • 1
  • 11
  • 25

0 Answers0