With GCC++ <= 9.3 the code below has compile error about using move constructor which is being deleted:
<source>: In constructor 'Widget::Widget()':
<source>:16:24: error: use of deleted function 'Child::Child(Child&&)'
16 | Widget() : m_array{} {}
| ^
<source>:11:5: note: declared here
11 | Child(Child&&) = delete;
| ^~~~~
With GCC++ >9.3 the error won’t be seen anymore.
Is it something about compiler specific issue or the code itself ?
As I comment in the code if the destructor is commented out the error won’t be seen.
https://godbolt.org/z/4s3o1sxPs
class Base {
public:
Base() {}
virtual ~Base() = default;//comment out error won't bee seen anymore
Base(Base&&) = delete;
};
class Child : public Base{
public:
Child() = default;
Child(Child&&) = delete;
};
class Widget {
public:
Widget() : m_array{} {}
private:
Child m_array[2];
};
int main()
{
Widget wd{};
}
>Solution :
Given that the behavior changed between gcc 9.3 and 9.4; this looks like a compiler bug that got fixed.
In fact, looking at the list of C++ compiler bugs fixed in gcc 9.4, it’s not hard to find https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63707 "Brace initialization of array sometimes fails if no copy constructor" which seems to be the bug you encountered.