This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR c++/67054 Allow inheriting constructor with non-default-constructible members
- From: Leonid Koppel <lkoppel at uwaterloo dot ca>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 26 Jul 2017 16:45:14 +0000
- Subject: [PATCH] PR c++/67054 Allow inheriting constructor with non-default-constructible members
- Authentication-results: sourceware.org; auth=none
- Authentication-results: mailchk-m01/v6QGjEuT031045; dmarc=fail (p=none dis=none) header.from=uwaterloo.ca
- Authentication-results: mailchk-m01; spf=fail smtp.mailfrom=lkoppel at uwaterloo dot ca
- Dkim-filter: OpenDKIM Filter v2.11.0 mailchk-m01.uwaterloo.ca v6QGjEuT031045
- Dmarc-filter: OpenDMARC Filter v1.3.2 mailchk-m01.uwaterloo.ca v6QGjEuT031045
This patch addresses PR 67054 (duplicates 62310, 80851). An implicitly-defined inheriting constructor was wrongly considered deleted when it would initialize a non-default-constructible member, even when a brace-or-equal-initializer was present.
The bug only affects deduction of the constructor's deletedness, not the actual generation of the constructor, which is why (I hope!) the fix might be so simple.
Tested on x86_64-pc-linux-gnu native.
Thanks,
Leo
2017-07-26 Leonid Koppel <lkoppel@uwaterloo.ca>
PR c++/67054 - Inheriting constructor with non-default-constructible members
* method.c (walk_field_subobs) Consider member initializers (NSDMIs) when
deducing an inheriting constructor.
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index cca1b146917..8b07f526473 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1342,7 +1342,7 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
if (bad && deleted_p)
*deleted_p = true;
}
- else if (sfk == sfk_constructor)
+ else if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
{
bool bad;
diff --git a/gcc/testsuite/g++.dg/cpp0x/inh-ctor29.C b/gcc/testsuite/g++.dg/cpp0x/inh-ctor29.C
new file mode 100644
index 00000000000..8e31f739d74
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/inh-ctor29.C
@@ -0,0 +1,23 @@
+// PR c++/67054
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+ A(int) {}
+};
+
+struct C
+{
+ C(int) {}
+};
+
+struct B : A
+{
+ using A::A;
+ C c = 42;
+};
+
+int main()
+{
+ B b = 24;
+}