that's value-initialization. */
if (init == void_type_node)
{
- /* If the type has data but no user-provided ctor, we need to zero
+ /* If the type has data but no user-provided default ctor, we need to zero
out the object. */
- if (!type_has_user_provided_constructor (type)
+ if (type_has_non_user_provided_default_constructor (type)
&& !is_really_empty_class (type, /*ignore_vptr*/true))
{
tree field_size = NULL_TREE;
--- /dev/null
+// PR c++/65816
+// { dg-do compile { target c++11 } }
+
+struct test {
+ int m;
+ test() = default;
+ constexpr test(int) : test() {}
+};
+
+static_assert(test(0).m == 0, "");
--- /dev/null
+// PR c++/65816
+// { dg-do run { target c++11 } }
+
+void* operator new(decltype(sizeof(int)), void* ptr) { return ptr; }
+
+struct test {
+ int i;
+ test() = default;
+ test(int) : test() {}
+};
+
+int main() {
+ alignas(test) unsigned char space[sizeof(test)];
+ for (auto& c : space) c = 0xff;
+
+ auto ptr = ::new(&space) test(42);
+ int& i = static_cast<test&>(*ptr).i;
+ if (i != 0) __builtin_abort();
+}
--- /dev/null
+// PR c++/65816
+// { dg-do run { target c++11 } }
+
+void* operator new(decltype(sizeof(int)), void* ptr) { return ptr; }
+
+struct item { int i; };
+
+struct collector : item {
+ int j;
+ collector() = default;
+ collector(int) {}
+};
+
+struct tuple : collector {
+ tuple() : collector() {}
+};
+
+int main() {
+ alignas(tuple) unsigned char space[sizeof(tuple)];
+ for (auto& c : space) c = 0xff;
+
+ auto ptr = ::new(&space) tuple;
+ int& i = static_cast<tuple&>(*ptr).i;
+ int& j = static_cast<tuple&>(*ptr).j;
+ if (i != 0 || j != 0) __builtin_abort();
+}
--- /dev/null
+// PR c++/65816
+// { dg-do compile { target c++20 } }
+
+struct X {
+ int i;
+ X() = default;
+ constexpr X(int) { }
+};
+
+struct Y : X {
+ constexpr Y() : X() { }
+};
+
+static_assert(Y().i == 0);
// { dg-do run { target c++11 } }
// { dg-options "-O0" }
-// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
#include <deque>
#include <testsuite_hooks.h>
// { dg-do run { target c++11 } }
// { dg-options "-O0" }
-// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
#include <forward_list>
#include <testsuite_hooks.h>
// { dg-do run { target c++11 } }
// { dg-options "-O0" }
-// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
#include <list>
#include <testsuite_hooks.h>
// { dg-do run { target c++11 } }
// { dg-options "-O0" }
-// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
#include <map>
#include <testsuite_hooks.h>
// { dg-do run { target c++11 } }
// { dg-options "-O0" }
-// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
#include <set>
#include <testsuite_hooks.h>
// { dg-do run { target c++11 } }
// { dg-options "-O0" }
-// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
#include <vector>
#include <testsuite_hooks.h>
// { dg-do run { target c++11 } }
// { dg-options "-O0" }
-// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
#include <vector>
#include <testsuite_hooks.h>