https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92393
Bug ID: 92393
Summary: Uniform initialization of non-copiable class data
member cause to error
Product: gcc
Version: 9.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: i.bubnikov at gmail dot com
Target Milestone: ---
This is the short example of code that doesn`t compile with GCC9.2 or previous
but it must to according to c++ standart.
class A
{
public:
A(){};
A(const A &)=delete;
~A(){}
};
class B
{
public:
B() : a{}
{}
A a[1];
};
int main()
{
B b;
}
According to c++17 standart:
If there are fewer initializer-clauses in the list than there are elements in a
non-union aggregate, then each element not explicitly initialized is
initialized as follows:
*If the element has a default member initializer ([class.mem]), the element is
initialized from that initializer.
*Otherwise, if the element is not a reference, the element is copy-initialized
from an empty initializer list ([dcl.init.list]).
*Otherwise, the program is ill-formed.
and
List-initialization of an object or reference of type T is defined as follows:
*[...]
*Otherwise, if the initializer list has no elements and T is a class type with
a default constructor, the object is value-initialized.
*[...]
Therefore, the default constructor of A is used directly. There's no copy
constructor involved.