public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9085] c++: __is_trivially_xible and multi-arg aggr paren init [PR102535]
@ 2021-10-06 14:15 Patrick Palka
0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-10-06 14:15 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d80c0e4584acc204ca9a2f8880ad455fef48371f
commit r11-9085-gd80c0e4584acc204ca9a2f8880ad455fef48371f
Author: Patrick Palka <ppalka@redhat.com>
Date: Thu Sep 30 17:54:17 2021 -0400
c++: __is_trivially_xible and multi-arg aggr paren init [PR102535]
is_xible_helper assumes only 0- and 1-argument ctors can be trivial, but
C++20 aggregate paren init means multi-arg ctors can now be trivial too.
This patch relaxes the relevant early exit check accordingly.
PR c++/102535
gcc/cp/ChangeLog:
* method.c (is_xible_helper): Don't exit early for multi-arg
ctors in C++20.
gcc/testsuite/ChangeLog:
* g++.dg/ext/is_trivially_constructible7.C: New test.
(cherry picked from commit 9845c52db38f15740861435f38f7e5ad8a8de2ec)
Diff:
---
gcc/cp/method.c | 4 +++-
.../g++.dg/ext/is_trivially_constructible7.C | 23 ++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 8d2f3ce30af..0489e2f9282 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -2092,8 +2092,10 @@ is_xible_helper (enum tree_code code, tree to, tree from, bool trivial)
tree expr;
if (code == MODIFY_EXPR)
expr = assignable_expr (to, from);
- else if (trivial && from && TREE_CHAIN (from))
+ else if (trivial && from && TREE_CHAIN (from)
+ && cxx_dialect < cxx20)
return error_mark_node; // only 0- and 1-argument ctors can be trivial
+ // before C++20 aggregate paren init
else if (TREE_CODE (to) == ARRAY_TYPE && !TYPE_DOMAIN (to))
return error_mark_node; // can't construct an array of unknown bound
else
diff --git a/gcc/testsuite/g++.dg/ext/is_trivially_constructible7.C b/gcc/testsuite/g++.dg/ext/is_trivially_constructible7.C
new file mode 100644
index 00000000000..38531074be3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_trivially_constructible7.C
@@ -0,0 +1,23 @@
+// PR c++/102535
+// Verify __is_trivially_constructible works with multi-arg paren init of
+// aggrs.
+// { dg-do compile { target c++11 } }
+
+struct A { int x; };
+struct B { float y; };
+struct C { char z; };
+struct D { A a; B b; C c; };
+
+template<class T, class... Ts>
+struct is_trivially_constructible {
+ static const bool value = __is_trivially_constructible(T, Ts...);
+};
+
+extern int n[1 + is_trivially_constructible<D, A>::value];
+extern int n[1 + is_trivially_constructible<D, A, B>::value];
+extern int n[1 + is_trivially_constructible<D, A, B, C>::value];
+#if __cpp_aggregate_paren_init
+extern int n[1 + true];
+#else
+extern int n[1 + false];
+#endif
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-06 14:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06 14:15 [gcc r11-9085] c++: __is_trivially_xible and multi-arg aggr paren init [PR102535] Patrick Palka
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).