C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: List initialization
From: Vladimir Grigoriev (vlad.moscow_at_[hidden])
Date: 2021-06-10 10:25:05


Now let’s consider the following example.
 
void g( const int ( & )[][2] )
{
    std::cout << "void g( const int ( & )[][2] )\n";
}
void g( const int ( & )[2][2] )
{
    std::cout << "void g( const int ( & )[2][2] )\n";
}
 
//…
 
g( { 1, 2, 3 } );
 
The MS VS 2019 issues an error that it is unable to convert the initializer list for either function.
 
Is it a compiler bug or does it behave correctly? In the last case what is the explanation of such a behavior?
 
With best regards,
Vlad from Moscow
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
 
 
>Четверг, 10 июня 2021, 15:37 +03:00 от Edward Catmur <ecatmur_at_[hidden]>:
> 
>On Thu, 10 Jun 2021 at 13:28, Vladimir Grigoriev via Std-Discussion < std-discussion_at_[hidden] > wrote:
>>Also is it this rule valid for designated initializations?
>> 
>>For example if we have
>> 
>>struct A
>>{
>>    int x, z;
>>};
>>struct B
>>{
>>    int x, y, z;
>>};
>>void g( const A & )
>>{
>>    std::cout << "void g( const A & )\n";
>>}
>>void g( const B & )
>>{
>>    std::cout << "void g( const B & )\n";
>>}
>> 
>>then is this call
>> 
>>    g( { .x = 1, .z = 2 } );
>> 
>>ambiguous or the function with the parameter const A & will be called?
> 
>A and B are not array types, so [over.ics.rank]/3.1.2 does not apply.
> 
>Indeed, all the compilers agree that the call is ambiguous.
 



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups