https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70395
Bug ID: 70395 Summary: [C++11] Error when initializing array of non-copyable non-trivial type in constructor initializer list Product: gcc Version: 5.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mosra at centrum dot cz Target Milestone: --- I am getting an error when trying to compile the following snippet: struct NonCopyable { NonCopyable(const NonCopyable&) = delete; NonCopyable(NonCopyable&&) = delete; NonCopyable& operator=(const NonCopyable&) = delete; NonCopyable& operator=(NonCopyable&&) = delete; NonCopyable() {} ~NonCopyable() {} // to make it non-trivial }; union A { A(): _a{} {} ~A() {} NonCopyable _a[5]; } a; int main() {} GCC 5.3 complains that `error: use of deleted function ‘NonCopyable::NonCopyable(NonCopyable&&)’`, both Clang 3.7 and MSVC 2015 compile fine. I really don't see why it should use a move constructor for initializing the elements. The behavior differs when I make the following changes: - If I make the `_a` member a non-array, it compiles fine. - If I remove the `NonCopyable` destructor, the struct is trivial again and everything compiles fine - If I use placement new instead of `_a{}`, everything compiles fine (but that's verbose) The behavior is the same for struct and union, I used union to emphasize that I need to do the initialization explicitly. This probably affects also older versions, didn't have a chance to test.