https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65816
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2015-04-20 00:00:00 |2017-6-8
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Probably not related to constructor delegation, because we also don't zero-init
the object in this case:
inline void* operator new(decltype(sizeof(0)), void* p) noexcept { return p; }
inline void operator delete (void*, void*) noexcept { }
struct X {
int i;
X() = default;
X(int) { }
};
struct Y : X {
Y() : X() { }
};
int main()
{
alignas(Y) char buf[sizeof(Y)] = { 1, 1, 1, 1 };
::new(buf) Y;
if (buf[0] || buf[1] || buf[2] || buf[3])
throw 1;
}
If the unused X(int) constructor isn't provided then we get the zero-init, so
it seems that the presence of *any* user-provided constructor affects the
interpretation of [dcl.init] p8, but it should only be affected by a
user-provided *default* constructor:
To value-initialize an object of type T means:
— if T is a (possibly cv-qualified) class type (Clause 12) with either no
default constructor (15.1) or a default constructor that is user-provided or
deleted, then the object is default-initialized;
— if T is a (possibly cv-qualified) class type without a user-provided or
deleted default constructor, then the object is zero-initialized and the
semantic constraints for default-initialization are checked, and if T
has a non-trivial default constructor, the object is default-initialized;
In the example that delegates to the default ctor there must be a user-provided
ctor to do the delegation, so it hits this bug.
This seems to be present in all GCC releases.