C++ PATCH for c++/11309 (value-initialization in new)
Jason Merrill
jason@redhat.com
Thu Jul 31 09:02:00 GMT 2008
While poking at 36633 I noticed that g++.dg/expr/anew4.C was XFAILed and
there didn't seem to be an open PR about it. So I reopened 11309 and
fixed the bug: basically, we were doing default-initialization for "new
T()", but the standard specifies value-initialization; these two differ
in that if a class has a non-trivial default constructor but not a
user-provided one, value-initialization will set its data members to 0,
whereas default-initialization won't.
I ran into some problems using build_value_init in these cases: building
up the initializer separately and then trying to apply it made the
compiler inappropriately use copy constructors and destructors. To get
around this I dropped the TARGET_EXPR around the AGGR_INIT_EXPR that
build_value_init returns, and pointed it at the object to be initialized
by just building up an INIT_EXPR. This feels a bit dodgy, but I think
it's the right approach.
Tested x86_64-pc-linux-gnu, applied to trunk.
More information about the Gcc-patches
mailing list