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

2024-11-11


2136. Argument-dependent lookup and initializer lists

Section: 6.5.4  [basic.lookup.argdep]     Status: NAD     Submitter: Ryou Ezoe     Date: 2015-06-10

Argument-dependent lookup does not consider the elements of an initializer list used as an argument. This seems inconsistent:

  namespace NS {
    struct X { } ;
    void f( std::initializer_list<X> ) { }
  }

  int main() {
    NS::X x ;
    // ADL fails to find NS::f
    f( {x,x,x} ) ;

    // OK. ADL finds NS::f
    auto i = {x,x,x} ;
    f( i ) ;

    // Also OK
    f( std::initializer_list<NS::X>{x,x,x} ) ;
  }

Rationale (October, 2015):

Argument-dependent lookup makes sense when the arguments correspond to actual parameters of the function. In the case of an initializer list, however, the elements of the initializer list need not bear any relationship to the actual parameter type of the function; instead, they provide values for aggregate initialization or construction of the object being initialized, and there is no reason to expect that that type will have the same associated namespace as the types of the elements of the initializer list.