C++ Logo

std-discussion

Advanced search

Re: List initialization

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Thu, 10 Jun 2021 13:25:57 +0100
On Thu, 10 Jun 2021 at 13:19, Vladimir Grigoriev <vlad.moscow_at_[hidden]>
wrote:

> So do I understand correctly that if there are the following
> overloaded functions
>
> void f( const int( & )[] ) // #1
> {
> std::cout << "void f( int & )[] )\n";
> }
> void f( const int( & )[2] ) // #2
> {
> std::cout << "void f( int & )[2] )\n";
> }
>
> then
>
> f( { 1, 2 } ); // calls #2
> f( { 1 } ); // calls #1
>

Yes, that's is a correct understanding of the overloading rules.

Although, Clang will erroneously call #2 in both cases.

Received on 2021-06-10 07:26:11