Question Details

No question body available.

Tags

c++ templates language-lawyer inner-classes local-class

Answers (3)

Accepted Answer Available
Accepted Answer
November 9, 2025 Score: 23 Rep: 123,367 Quality: Expert Completeness: 70%

Core issue 2936, which is fairly recent, made typename not required when naming a (type) member of a local class. This resolution is a Defect Report, which will become official when C++26 is published and will also be considered to apply to older language versions.

The standard uses a broad brush when painting names as dependent. Some of those names don't really depend on the template arguments, but in terms of specification, it's more correct to make too many names dependent than too few (because if something should be dependent and isn't, then compilers will have difficulty with parsing it if the user isn't required to use typename). However, if there's an obvious category of names that shouldn't be dependent but are, it's a usability issue and should be corrected. That is what was done in this case (26 years after the original C++ standard was published).

November 9, 2025 Score: 7 Rep: 21,100 Quality: High Completeness: 100%

Here A::B is not a dependent name, and so typename is not (formally) required.

[temp.dep.type]/5:

A qualified name is dependent if

  • it is a conversion-function-id whose conversion-type-id is dependent, or
  • its lookup context is dependent and is not the current instantiation, or
  • its lookup context is the current instantiation and it is operator= or
  • its lookup context is the current instantiation and has at least one dependent base class, and qualified name lookup for the name finds nothing.

The name B is not a conversion-function-id, and is not operator=. Its lookup context A is a local class, which is the current instantiation ([temp.dep.type]/1), and has no dependent base class. So B is not a dependent name. It should be found by usual name lookup, and get resolved as a type name without the help of typename.

In practice, though, it seems that compilers are rather conservative and treat more names as dependent than the standard requires.

November 13, 2025 Score: -2 Rep: 1 Quality: Low Completeness: 50%

The short answer is: Clang and GCC are correct. You must use typename A::B

The compilers that accept A::B() or A::B{} without typename are non-compliant in this case.

Why typename is Required Here?

The rule is that you must use the typename keyword to prefix any dependent qualified name that refers to a type.

The entire issue boils down to one question: Is A::B a dependent name? The answer is yes.