re PR c++/92869 (C++17 wrongly reports aggregate type as not-aggregate (when explicit...
authorJakub Jelinek <jakub@redhat.com>
Wed, 11 Dec 2019 18:44:02 +0000 (19:44 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 11 Dec 2019 18:44:02 +0000 (19:44 +0100)
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
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/aggr3.C [new file with mode: 0644]

index 5a2ba31a6e037f2a633629f65c343b3994451bb2..d8a6ae3dd0d06a69b40eb8165f8f168f0404bed6 100644 (file)
@@ -1,3 +1,10 @@
+2019-12-11  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <polacek@redhat.com>
 
        PR c++/92878 - Parenthesized init of aggregates in new-expression.
index a8c6b1cb01c78fb707488505a4d1dad6f9edf87b..9b0cf503a34873b12b793bb30d1d1b5089446c98 100644 (file)
@@ -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.  */
index aac5a76823c489b8f8e611fd55b04f42c2df79d6..0c22a9cdd2f8047d8d2ae054424ecff84ff8b28d 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/92869
+       * g++.dg/cpp0x/aggr3.C: New test.
+
 2019-12-11  Marek Polacek  <polacek@redhat.com>
 
        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 (file)
index 0000000..5b06ed0
--- /dev/null
@@ -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 <typename T, int N>
+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<int, 3> b = { { 1, 2, 3 } }; // { dg-error "could not convert" "" { target c++2a } }