Re: [PATCH] c++: default ctor that's also a list ctor [PR102050]

2021-09-15 Thread Jason Merrill via Gcc-patches

On 9/14/21 15:16, Patrick Palka wrote:

In grok_special_member_properties we need to set TYPE_HAS_COPY_CTOR,
TYPE_HAS_DEFAULT_CONSTRUCTOR and TYPE_HAS_LIST_CTOR independently
from each other because a single constructor can be both a default and
list constructor (as in the first testcase), or both a default and copy
constructor (as in the second testcase).

Bootstrapped and regtested on x86_64-pc-linux-gsu, does this look OK for
trunk?


OK.


PR c++/102050

gcc/cp/ChangeLog:

* decl.c (grok_special_member_properties): Set
TYPE_HAS_COPY_CTOR, TYPE_HAS_DEFAULT_CONSTRUCTOR
and TYPE_HAS_LIST_CTOR independently from each other.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist125.C: New test.
* g++.dg/cpp0x/initlist126.C: New test.
---
  gcc/cp/decl.c|  6 --
  gcc/testsuite/g++.dg/cpp0x/initlist125.C | 10 ++
  gcc/testsuite/g++.dg/cpp0x/initlist126.C | 17 +
  3 files changed, 31 insertions(+), 2 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist125.C
  create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist126.C

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 1a2925b4108..76e4e6e8a26 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -14843,9 +14843,11 @@ grok_special_member_properties (tree decl)
  if (ctor > 1)
TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
}
-  else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
+
+  if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
-  else if (is_list_ctor (decl))
+
+  if (is_list_ctor (decl))
TYPE_HAS_LIST_CTOR (class_type) = 1;
  
if (DECL_DECLARED_CONSTEXPR_P (decl)

diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist125.C 
b/gcc/testsuite/g++.dg/cpp0x/initlist125.C
new file mode 100644
index 000..08ae3741c67
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist125.C
@@ -0,0 +1,10 @@
+// PR c++/102050
+// { dg-do compile { target c++11 } }
+
+#include 
+
+struct A { A(std::initializer_list = {}); };
+
+A x{0};
+A y{1, 2, 3};
+A z;
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist126.C 
b/gcc/testsuite/g++.dg/cpp0x/initlist126.C
new file mode 100644
index 000..0a8fb998be6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist126.C
@@ -0,0 +1,17 @@
+// PR c++/102050
+// { dg-do compile { target c++11 } }
+
+#include 
+
+extern struct A a;
+
+struct A {
+  A(const A& = a);
+  A(std::initializer_list) = delete;
+};
+
+void f(A);
+
+int main() {
+  f({}); // { dg-bogus "deleted" }
+}





[PATCH] c++: default ctor that's also a list ctor [PR102050]

2021-09-14 Thread Patrick Palka via Gcc-patches
In grok_special_member_properties we need to set TYPE_HAS_COPY_CTOR,
TYPE_HAS_DEFAULT_CONSTRUCTOR and TYPE_HAS_LIST_CTOR independently
from each other because a single constructor can be both a default and
list constructor (as in the first testcase), or both a default and copy
constructor (as in the second testcase).

Bootstrapped and regtested on x86_64-pc-linux-gsu, does this look OK for
trunk?

PR c++/102050

gcc/cp/ChangeLog:

* decl.c (grok_special_member_properties): Set
TYPE_HAS_COPY_CTOR, TYPE_HAS_DEFAULT_CONSTRUCTOR
and TYPE_HAS_LIST_CTOR independently from each other.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist125.C: New test.
* g++.dg/cpp0x/initlist126.C: New test.
---
 gcc/cp/decl.c|  6 --
 gcc/testsuite/g++.dg/cpp0x/initlist125.C | 10 ++
 gcc/testsuite/g++.dg/cpp0x/initlist126.C | 17 +
 3 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist125.C
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist126.C

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 1a2925b4108..76e4e6e8a26 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -14843,9 +14843,11 @@ grok_special_member_properties (tree decl)
  if (ctor > 1)
TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
}
-  else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
+
+  if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
-  else if (is_list_ctor (decl))
+
+  if (is_list_ctor (decl))
TYPE_HAS_LIST_CTOR (class_type) = 1;
 
   if (DECL_DECLARED_CONSTEXPR_P (decl)
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist125.C 
b/gcc/testsuite/g++.dg/cpp0x/initlist125.C
new file mode 100644
index 000..08ae3741c67
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist125.C
@@ -0,0 +1,10 @@
+// PR c++/102050
+// { dg-do compile { target c++11 } }
+
+#include 
+
+struct A { A(std::initializer_list = {}); };
+
+A x{0};
+A y{1, 2, 3};
+A z;
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist126.C 
b/gcc/testsuite/g++.dg/cpp0x/initlist126.C
new file mode 100644
index 000..0a8fb998be6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist126.C
@@ -0,0 +1,17 @@
+// PR c++/102050
+// { dg-do compile { target c++11 } }
+
+#include 
+
+extern struct A a;
+
+struct A {
+  A(const A& = a);
+  A(std::initializer_list) = delete;
+};
+
+void f(A);
+
+int main() {
+  f({}); // { dg-bogus "deleted" }
+}
-- 
2.33.0.328.g8b7c11b866