From 3455115379cef3a84ce8154b6c4316ed7585f73f Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 11 Dec 2019 19:44:02 +0100 Subject: [PATCH] re PR c++/92869 (C++17 wrongly reports aggregate type as not-aggregate (when explicitly defaulted ctors are added)) PR c++/92869 * class.c (finish_struct): For C++17 and earlier, check type_has_user_provided_or_explicit_constructor rather than TYPE_HAS_USER_CONSTRUCTOR whether to set CLASSTYPE_NON_AGGREGATE. * g++.dg/cpp0x/aggr3.C: New test. From-SVN: r279241 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/class.c | 8 +++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/aggr3.C | 20 ++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/aggr3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5a2ba31a6e0..d8a6ae3dd0d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2019-12-11 Jakub Jelinek + + PR c++/92869 + * class.c (finish_struct): For C++17 and earlier, check + type_has_user_provided_or_explicit_constructor rather than + TYPE_HAS_USER_CONSTRUCTOR whether to set CLASSTYPE_NON_AGGREGATE. + 2019-12-11 Marek Polacek PR c++/92878 - Parenthesized init of aggregates in new-expression. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index a8c6b1cb01c..9b0cf503a34 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -7474,7 +7474,13 @@ finish_struct (tree t, tree attributes) /* Remember current #pragma pack value. */ TYPE_PRECISION (t) = maximum_field_alignment; - if (TYPE_HAS_USER_CONSTRUCTOR (t)) + if (cxx_dialect < cxx2a) + { + if (!CLASSTYPE_NON_AGGREGATE (t) + && type_has_user_provided_or_explicit_constructor (t)) + CLASSTYPE_NON_AGGREGATE (t) = 1; + } + else if (TYPE_HAS_USER_CONSTRUCTOR (t)) CLASSTYPE_NON_AGGREGATE (t) = 1; /* Fix up any variants we've already built. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index aac5a76823c..0c22a9cdd2f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-12-11 Jakub Jelinek + + PR c++/92869 + * g++.dg/cpp0x/aggr3.C: New test. + 2019-12-11 Marek Polacek PR c++/92878 - Parenthesized init of aggregates in new-expression. diff --git a/gcc/testsuite/g++.dg/cpp0x/aggr3.C b/gcc/testsuite/g++.dg/cpp0x/aggr3.C new file mode 100644 index 00000000000..5b06ed08d71 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/aggr3.C @@ -0,0 +1,20 @@ +// PR c++/92869 +// { dg-do compile { target c++11 } } + +struct A { + A () = default; + A (const A &) = default; + A (A &&) = default; + int arr[3]; +}; + +template +struct B { + B () = default; + B (const B &) = default; + B (B &&) = default; + T arr[N]; +}; + +A a = { { 1, 2, 3 } }; // { dg-error "could not convert" "" { target c++2a } } +B b = { { 1, 2, 3 } }; // { dg-error "could not convert" "" { target c++2a } } -- 2.30.2