Title
Use of the typename keyword in return types
Status
nad
Section
13.8 [temp.res]
Submitter
Greg Comeau

Created on 2006-02-11.00:00:00 last changed 46 months ago

Messages

Date: 2021-02-15.00:00:00

Rationale (February, 2021):

The current wording of 13.8.1 [temp.res.general] bullet 5.2.1 makes clear that the typename keyword is not required for the given example.

Date: 2022-11-20.07:54:16

Consider the following example:

    template <class T> struct Outer {
        struct Inner {
            Inner* self();
        };
    };
    template <class T> Outer<T>::Inner*
        Outer<T>::Inner::self() { return this; }

According to 13.8 [temp.res] paragraph 3 (before the salient wording was inadvertently removed, see issue 559),

A qualified-id that refers to a type and in which the nested-name-specifier depends on a template-parameter (13.8.3 [temp.dep]) but does not refer to a member of the current instantiation (13.8.3.2 [temp.dep.type]) shall be prefixed by the keyword typename to indicate that the qualified-id denotes a type, forming a typename-specifier.

Because Outer<T>::Inner is a member of the current instantiation, the Standard does not currently require that it be prefixed with typename when it is used in the return type of the definition of the self() member function. However, it is difficult to parse this definition correctly without knowing that the return type is, in fact, a type, which is what the typename keyword is for. Should the Standard be changed to require typename in such contexts?

History
Date User Action Args
2021-02-17 00:00:00adminsetmessages: + msg6513
2021-02-17 00:00:00adminsetstatus: drafting -> nad
2006-04-22 00:00:00adminsetstatus: open -> drafting
2006-02-11 00:00:00admincreate