* [C++2A] Implement P1008R1 - prohibit aggregates with user-declared constructors
@ 2018-07-30 11:01 Jakub Jelinek
2018-07-31 14:12 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2018-07-30 11:01 UTC (permalink / raw)
To: Nathan Sidwell, Jason Merrill; +Cc: gcc-patches
Hi!
Seems what is considered an aggregate type keeps changing in every single
C++ version.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2018-07-27 Jakub Jelinek <jakub@redhat.com>
P1008R1 - prohibit aggregates with user-declared constructors
* class.c (check_bases_and_members): For C++2a set
CLASSTYPE_NON_AGGREGATE based on TYPE_HAS_USER_CONSTRUCTOR rather than
type_has_user_provided_or_explicit_constructor.
* g++.dg/ext/is_aggregate.C: Add tests with deleted or defaulted ctor.
* g++.dg/cpp0x/defaulted1.C (main): Ifdef out for C++2a B b = {1};.
* g++.dg/cpp0x/deleted2.C: Expect error for C++2a.
* g++.dg/cpp2a/aggr1.C: New test.
* g++.dg/cpp2a/aggr2.C: New test.
--- gcc/cp/class.c.jj 2018-07-25 18:46:56.168149411 +0200
+++ gcc/cp/class.c 2018-07-27 21:21:22.382933221 +0200
@@ -5571,7 +5571,9 @@ check_bases_and_members (tree t)
Again, other conditions for being an aggregate are checked
elsewhere. */
CLASSTYPE_NON_AGGREGATE (t)
- |= (type_has_user_provided_or_explicit_constructor (t)
+ |= ((cxx_dialect < cxx2a
+ ? type_has_user_provided_or_explicit_constructor (t)
+ : TYPE_HAS_USER_CONSTRUCTOR (t))
|| TYPE_POLYMORPHIC_P (t));
/* This is the C++98/03 definition of POD; it changed in C++0x, but we
retain the old definition internally for ABI reasons. */
--- gcc/testsuite/g++.dg/ext/is_aggregate.C.jj 2017-03-31 08:39:08.141481789 +0200
+++ gcc/testsuite/g++.dg/ext/is_aggregate.C 2018-07-27 21:46:58.832053123 +0200
@@ -61,6 +61,8 @@ struct K { int a, b; virtual void foo ()
struct L : virtual public A { int d, e; };
struct M : protected A { int d, e; };
struct N : private A { int d, e; };
+struct O { O () = delete; int a, b, c; };
+struct P { P () = default; int a, b, c; };
typedef int T;
typedef float U;
typedef int V __attribute__((vector_size (4 * sizeof (int))));
@@ -94,6 +96,13 @@ main ()
assert (NTEST (L));
assert (NTEST (M));
assert (NTEST (N));
+#if __cplusplus > 201703L
+ assert (NTEST (O));
+ assert (NTEST (P));
+#else
+ assert (PTEST (O));
+ assert (PTEST (P));
+#endif
assert (PTEST (int[]));
assert (PTEST (double[]));
assert (PTEST (T[2]));
@@ -114,4 +123,6 @@ main ()
assert (PTEST (L[]));
assert (PTEST (M[6]));
assert (PTEST (N[]));
+ assert (PTEST (O[]));
+ assert (PTEST (P[]));
}
--- gcc/testsuite/g++.dg/cpp0x/defaulted1.C.jj 2014-03-10 10:50:13.280983792 +0100
+++ gcc/testsuite/g++.dg/cpp0x/defaulted1.C 2018-07-27 22:03:48.425103195 +0200
@@ -23,7 +23,9 @@ struct B
int main()
{
A a1, a2;
+#if __cplusplus <= 201703L
B b = {1};
+#endif
a1 = a2;
}
--- gcc/testsuite/g++.dg/cpp0x/deleted2.C.jj 2013-12-09 14:32:14.279033576 +0100
+++ gcc/testsuite/g++.dg/cpp0x/deleted2.C 2018-07-27 22:04:35.539198867 +0200
@@ -6,4 +6,4 @@ struct A {
A() = delete;
};
-A a = {1};
+A a = {1}; // { dg-error "could not convert" "" { target c++2a } }
--- gcc/testsuite/g++.dg/cpp2a/aggr1.C.jj 2018-07-27 21:33:20.566391559 +0200
+++ gcc/testsuite/g++.dg/cpp2a/aggr1.C 2018-07-27 22:06:09.093388836 +0200
@@ -0,0 +1,15 @@
+// { dg-do compile { target c++11 } }
+struct A {
+ A () = delete; // { dg-message "declared here" "" { target c++2a } }
+};
+struct B {
+ B () = default;
+ int b = 0;
+};
+struct C {
+ C (C&&) = default; // { dg-message "candidate" "" { target c++2a } }
+ int c, d;
+};
+A a {}; // { dg-error "use of deleted function" "" { target c++2a } }
+B b = {1}; // { dg-error "could not convert" "" { target { c++11_only || c++2a } } }
+C *c = new C {2, 3}; // { dg-error "no matching function for call to" "" { target c++2a } }
--- gcc/testsuite/g++.dg/cpp2a/aggr2.C.jj 2018-07-27 22:10:51.956963223 +0200
+++ gcc/testsuite/g++.dg/cpp2a/aggr2.C 2018-07-27 22:15:20.820509168 +0200
@@ -0,0 +1,25 @@
+// { dg-do run { target c++11 } }
+
+struct A;
+struct B { operator A (); };
+struct A { A (const A &) = default; A () = default; B a; };
+A a {B {}};
+bool seen;
+
+B::operator A ()
+{
+ seen = true;
+ return A ();
+}
+
+int
+main ()
+{
+#if __cplusplus > 201703L
+ if (!seen)
+ __builtin_abort ();
+#else
+ if (seen)
+ __builtin_abort ();
+#endif
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++2A] Implement P1008R1 - prohibit aggregates with user-declared constructors
2018-07-30 11:01 [C++2A] Implement P1008R1 - prohibit aggregates with user-declared constructors Jakub Jelinek
@ 2018-07-31 14:12 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-07-31 14:12 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Nathan Sidwell, gcc-patches List
On Mon, Jul 30, 2018 at 9:01 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Seems what is considered an aggregate type keeps changing in every single
> C++ version.
Indeed :/
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
This is OK. I think we could also use a -Wc++2a-compat warning, and
an inform in 2a mode about why your initializer doesn't work any more,
but they don't need to go in right now.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-31 14:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-30 11:01 [C++2A] Implement P1008R1 - prohibit aggregates with user-declared constructors Jakub Jelinek
2018-07-31 14:12 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).