Template parameters in member selections
_N4868_.6.5.6 [basic.lookup.classref]
Daveed Vandevoorde

Created on 2010-06-29.00:00:00 last changed 11 months ago


Date: 2020-11-15.00:00:00

Additional note (November, 2020):

Paper P1787R6, adopted at the November, 2020 meeting, partially addresses this issue.

Date: 2010-06-29.00:00:00

In an example like

    template<typename T> void f(T p)->decltype(p.T::x);

The nested-name-specifier T:: looks like it refers to the template parameter. However, if this is instantiated with a type like

    struct T { int x; };
    struct S: T { };

the reference will be ambiguous, since it is looked up in both the context of the expression, finding the template parameter, and in the class, finding the base class injected-class-name, and this could be a deduction failure. As a result, the same declaration with a different parameter name

    template<typename U> void f(U p)->decltype(p.U::x);

is, in fact, not a redeclaration because the two can be distinguished by SFINAE.

It would be better to add a new lookup rule that says that if a name in a template definition resolves to a template parameter, that name is not subject to further lookup at instantiation time.

Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6230
2010-06-29 00:00:00admincreate