This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


183. typename in explicit specializations

Section: 13.8  [temp.res]     Status: TC1     Submitter: John Spicer     Date: 9 Nov 1999

John Spicer: In 13.8 [temp.res] paragraph 5, the standard says

The keyword typename shall only be used in template declarations and definitions...
My understanding of the intent of this restriction is to say that typename is only allowed in contexts in which template dependent names can be found, but the wording leaves open to interpretation whether typename is allowed in an explicit specialization, such as:
    template <class T> struct A {};
    template <class T> struct B { typedef int X; };
    template <> struct A<int> {
        typename B<int>::X x;
    };
My understanding is that such usage is not permitted. This should be clarified one way or the other.

Mike Miller: I agree with your understanding that you are not allowed to use typename in an explicit specialization. However, I think the standard already says that — an explicit specialization is not a template declaration. According to the grammar in Clause 13 [temp] paragraph 1, a template-declaration must have a non-empty template-parameter-list.

Nathan Myers: Is there any actual reason for this restriction? Its only apparent effect is to make it harder to specialize templates, with no corresponding benefit.

Proposed resolution (10/00):

In 13.8 [temp.res] paragraph 5, replace

The keyword typename shall only be applied to qualified names, but those names need not be dependent.

with

The keyword typename shall be applied only to qualified names, but those names need not be dependent. The keyword typename shall be used only in contexts in which dependent names can be used. This includes template declarations and definitions but excludes explicit specialization declarations and explicit instantiation declarations.