Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependent qualified name lookup in C++14

This is about dependent name lookup in a template function, for example:

template<class T>
void foo(T const &t)
{
    ::func(t);
}

In this code, func is a dependent name because it has a type-dependent expression as argument to a function call. In C++11 the lookup for func was covered by [temp.dep.candidate]/1:

For a function call that depends on a template parameter, the candidate functions are found using the usual lookup rules (3.4.1, 3.4.2, 3.4.3) except that:

  • For the part of the lookup using unqualified name lookup (3.4.1) or qualified name lookup (3.4.3), only function declarations from the template definition context are found.
  • For the part of the lookup using associated namespaces (3.4.2), only function declarations found in either the template definition context or the template instantiation context are found.

[Note: 3.4.1 is "ordinary" unqualified-id lookup, and 3.4.2 is unqualified-id lookup for function names, aka. ADL, and 3.4.3 is qualified-id lookup].

However in C++14 (N3936) the parts about qualified-id lookup were removed:

For a function call where the postfix-expression is a dependent name, the candidate functions are found using the usual lookup rules (3.4.1, 3.4.2) except that:

  • For the part of the lookup using unqualified name lookup (3.4.1), only function declarations from the template definition context are found.
  • For the part of the lookup using associated namespaces (3.4.2), only function declarations found in either the template definition context or the template instantiation context are found.

Assuming that this change was done on purpose; which clauses now cover the finding of candidate functions for a function call where the postfix-expression is a dependent name and a qualified-id ?

(Background: I am looking for confirmation that qualified name lookup still only looks in the template definition context, not the instantiation context).

like image 395
M.M Avatar asked Oct 20 '22 22:10

M.M


1 Answers

Defect report 1321 has been accepted into the latest C++14 draft (N4140). This defect report clarifies the equivalency of dependent names, and at the same time clarifies that a dependent name must be an unqualified-id. Formerly, in C++11, dependent names could be arbitrary id-expressions.

This means that qualified-id names are no longer dependent names, and are therefore looked up according to §14.6.3 [temp.nondep]. This doesn't actually affect program behaviour from C++11, since dependent names only affect whether ADL (§3.4.2) is performed with the template instantiation context, and only unqualified-ids are eligible for ADL anyway.

like image 97
nneonneo Avatar answered Oct 27 '22 00:10

nneonneo