Title
Argument-dependent lookup and initializer lists
Status
nad
Section
6.5.4 [basic.lookup.argdep]
Submitter
Ryou Ezoe

Created on 2015-06-10.00:00:00 last changed 109 months ago

Messages

Date: 2015-10-15.00:00:00

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.

Date: 2022-11-20.07:54:16

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} ) ;
  }
History
Date User Action Args
2015-11-10 00:00:00adminsetmessages: + msg5972
2015-06-10 00:00:00admincreate