Juha Nieminen <nos...@thanks.invalid> writes:
> Consider the following code:
>
> //--------------------------------------------------
> struct A { int values[5]; A(): values{} {} };
> struct B { int values[5] = {}; };
> int main()
> {
> const A a; // Works
> const B b; // Compiler error
> }
> //--------------------------------------------------
>
> This compiles with all recent versions of gcc. However, all recent versions
> of clang complain about the "const B b;" line, saying:
> "error: default initialization of an object of const type 'const B' without
> a user-provided default constructor"
>
> Which one is right?
In N4296: §8.5p7 is:
| To default-initialize an object of type T means:
|
| (7.1) — If T is a (possibly cv-qualified) class type (Clause 9),
| constructors are considered. The applicable constructors are enumerated
| (13.3.1.3), and the best one for the initializer () is chosen through
| overload resolution (13.3). The constructor thus selected is called,
| with an empty argument list, to initialize the object.
|
| (7.2) — If T is an array type, each element is default-initialized.
|
| (7.3) — Otherwise, no initialization is performed.
|
| If a program calls for the default initialization of an object of a
| const-qualified type T, T shall be a class type with a user-provided
| default constructor.
So I think clang is right.
-- Alain.