Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Aggregate initialization of base class sub-object, what?

25 views
Skip to first unread message

Alf P. Steinbach

unread,
Mar 5, 2020, 8:27:54 PM3/5/20
to
Why does this compile as C++17 with MinGW g++ 9.2 and Visual C++ 2019?


#include <string>

struct Top { friend void g() {} };

struct Blah: Top
{
int a = 1;
int b = a;
};

auto main() -> int
{
Blah b{ {}, 3, 42 };
(void) b;
return b.b;
}


Result: exit code 42.

- Alf

Ian Collins

unread,
Mar 6, 2020, 4:40:46 PM3/6/20
to
On 06/03/2020 14:27, Alf P. Steinbach wrote:
> Why does this compile as C++17 with MinGW g++ 9.2 and Visual C++ 2019?
>
>
> #include <string>
>
> struct Top { friend void g() {} };
>
> struct Blah: Top
> {
> int a = 1;
> int b = a;
> };
>
> auto main() -> int
> {
> Blah b{ {}, 3, 42 };
> (void) b;
> return b.b;
> }

Wasn't the aggregate initialisation of base class sub-object introduced
in C++17?

--
Ian.

Vir Campestris

unread,
Mar 6, 2020, 4:43:36 PM3/6/20
to
OK with GCC 7.4.0 too. Where there's no need for the friend, the
initialiser values in Blah, or the (void)b.

But I'm not sure I see the problem. Unless you're asking why it _only_
compiles with 17, and not with 11 - in which case I'm confused too.

Andy
0 new messages