C++ Logo

std-discussion

Advanced search

Re: List initialization

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Thu, 10 Jun 2021 13:37:34 +0100
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.

Received on 2021-06-10 07:37:48