On 9/30/21 12:52, Patrick Palka wrote:
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.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/11?
OK.
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.
---
gcc/cp/method.c | 4 +++-
.../g++.dg/ext/is_trivially_constructible7.C | 17 +++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/ext/is_trivially_constructible7.C
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 3c3495227ce..c38912a7ce9 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -2094,8 +2094,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..f6fbf8f2d9e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/is_trivially_constructible7.C
@@ -0,0 +1,17 @@
+// PR c++/102535
+// Verify __is_trivially_constructible works with multi-arg paren init of
+// aggrs.
+
+struct A { int x; };
+struct B { float y; };
+struct C { char z; };
+struct D { A a; B b; C c; };
+
+extern int n[1 + __is_trivially_constructible(D, A)];
+extern int n[1 + __is_trivially_constructible(D, A, B)];
+extern int n[1 + __is_trivially_constructible(D, A, B, C)];
+#if __cpp_aggregate_paren_init
+extern int n[1 + true];
+#else
+extern int n[1 + false];
+#endif