Date: Fri, 27 Nov 2020 22:06:32 +0300
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.
As a result we get that 2 is equal to 1.:)
Or do I have missed something?
With best regards,
(Vlad from Moscow)
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
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.
As a result we get that 2 is equal to 1.:)
Or do I have missed something?
With best regards,
(Vlad from Moscow)
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
Received on 2020-11-27 13:06:37