This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR c++/67054 Allow inheriting constructor with non-default-constructible members
- From: Jason Merrill <jason at redhat dot com>
- To: Leonid Koppel <lkoppel at uwaterloo dot ca>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 26 Jul 2017 12:52:00 -0400
- Subject: Re: [PATCH] PR c++/67054 Allow inheriting constructor with non-default-constructible members
- Authentication-results: sourceware.org; auth=none
- References: <84a1172988e14a7caf7c78cbaed2a3ff@uwaterloo.ca>
OK, thanks.
On Wed, Jul 26, 2017 at 12:45 PM, Leonid Koppel <lkoppel@uwaterloo.ca> wrote:
> 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;
> +}