[Bug c++/40239] New: Aggregate initialization requires copy constructor
schaub-johannes at web dot de
gcc-bugzilla@gcc.gnu.org
Mon May 25 00:06:00 GMT 2009
GCC 4.4.0 (and earlier) requires a copy constructor for elements that are not
explicitly initialized using a non-empty aggregate initializer list. Thus the
following fails
struct B { B() { } private: B(B const&); };
struct A { int a; B b; };
int main() {
A a = { 0 };
}
main.cpp: In function 'int main()':
main.cpp:1: error: 'B::B(const B&)' is private
main.cpp:5: error: within this context
The Standard says any not explicitly ininitialized element is
value-initialized. In the above sample, that should call the default
constructor. The copy constructor is required only when using an empty
aggregate initializer:
struct B { B() { } private: B(B const&); };
struct A { int a; B b; };
int main() {
A a = { };
}
In which case any element should be initialized from an expression of the form
T(), with T being the type of the element. GCC correctly rejects that example,
but incorrectly rejects the first example.
Note that C++0x will make both examples valid (in the latest draft, at least),
and GCC should not reject any of them.
--
Summary: Aggregate initialization requires copy constructor
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: schaub-johannes at web dot de
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40239
More information about the Gcc-bugs
mailing list