C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Aggregate elements
From: Jason McKesson (jmckesson_at_[hidden])
Date: 2020-11-28 10:33:23


On Fri, Nov 27, 2020 at 2:07 PM Vladimir Grigoriev via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> It seems there is a problem with the arithmetic relative to aggregates (C++ 20, 9.4.1 Aggregates)
>
> The elements of an aggregate are defined the following way
>
> 2 The elements of an aggregate are:
> (2.2) -- for a class, the direct base classes in declaration order, followed by the direct non-static data members (11.4) that are not members of an anonymous union, in declaration order
>
> So for example if we have
>
> struct A
> {
> int x, y;
> };
>
> struct B : A
> {
> int z;
> };
>
> then according to the quote the aggregate B has only two elements: the direct base class A and the direct non-static data member z.
>
> Now consider the initialization of an object of the aggregate
>
> B b = { 1, 2 };
>
> and let's read another quote from this section
>
> 3 When an aggregate is initialized by an initializer list as specified in 9.4.4, the elements of the initializer list are taken as initializers for the elements of the aggregate. The explicitly initialized elements of the aggregate are determined as follows:
> (3.2) -- If the initializer list is an initializer-list, the explicitly initialized elements of the aggregate are the first n elements of the aggregate, where n is the number of elements in the initializer list.
>
> So according to the quote we have two explicitly initialized elements of the aggregate corresponding to the number of initializers when actually only one element of the aggregate, its direct base class, was initialized.

There are two aggregate types involved in this example. In which
circumstances is the text "the aggregate" referring `A` and to `B`?

Once you work that out, it makes sense.


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

Older Archives on Google Groups