aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-06-05 14:22:35 -0400
committerMarek Polacek <polacek@redhat.com>2020-06-05 15:51:08 -0400
commitcecc73af4980004502f4c327b6c639125defb379 (patch)
treea15c8551d20854becb91364baad2b8bfa8d720c9 /gcc
parentbcd96c9cce962ca5b2c6f8459597fb759f945ccf (diff)
downloadgcc-cecc73af4980004502f4c327b6c639125defb379.zip
gcc-cecc73af4980004502f4c327b6c639125defb379.tar.gz
gcc-cecc73af4980004502f4c327b6c639125defb379.tar.bz2
c++: Make braced-init-list as template arg work with aggr init [PR95369]
Barry pointed out to me that our braced-init-list as a template-argument extension doesn't work as expected when we aggregate-initialize. Since aggregate list-initialization is a user-defined conversion sequence, we allow it as part of a converted constant expression. Co-authored-by: Jason Merrill <jason@redhat.com> gcc/cp/ChangeLog: PR c++/95369 * call.c (build_converted_constant_expr_internal): Allow list-initialization. gcc/testsuite/ChangeLog: PR c++/95369 * g++.dg/cpp2a/nontype-class38.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/call.c4
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/nontype-class38.C30
2 files changed, 33 insertions, 1 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 2b393f9..3c97b98 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4348,7 +4348,7 @@ build_converted_constant_expr_internal (tree type, tree expr,
and where the reference binding (if any) binds directly. */
for (conversion *c = conv;
- conv && c->kind != ck_identity;
+ c && c->kind != ck_identity;
c = next_conversion (c))
{
switch (c->kind)
@@ -4356,6 +4356,8 @@ build_converted_constant_expr_internal (tree type, tree expr,
/* A conversion function is OK. If it isn't constexpr, we'll
complain later that the argument isn't constant. */
case ck_user:
+ /* List-initialization is OK. */
+ case ck_aggr:
/* The lvalue-to-rvalue conversion is OK. */
case ck_rvalue:
/* Array-to-pointer and function-to-pointer. */
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class38.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class38.C
new file mode 100644
index 0000000..5b440fd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class38.C
@@ -0,0 +1,30 @@
+// PR c++/95369
+// { dg-do compile { target c++20 } }
+
+struct S {
+ int a;
+ int b;
+};
+
+struct W {
+ int i;
+ S s;
+};
+
+template <S p>
+void fnc()
+{
+}
+
+template<S s> struct X { };
+template<W w> struct Y { };
+
+void f()
+{
+ fnc<{ .a = 10, .b = 20 }>();
+ fnc<{ 10, 20 }>();
+ X<{ .a = 1, .b = 2 }> x;
+ X<{ 1, 2 }> x2;
+ // Brace elision is likely to be allowed.
+ Y<{ 1, 2, 3 }> x3;
+}