From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2100) id A74C53850410; Sat, 22 Aug 2020 22:07:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A74C53850410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598134062; bh=KoOTYHfrYM5m+CTRo6Y53xD/t1Khdzix3BYoxMQkLBs=; h=From:To:Subject:Date:From; b=OAOl5fGbiJ2u/zgtiaUmxuHNVmntcEr6BHFSH2WDAc5vvZkhc5yX9XNOwhDJWxHu2 4a3TgEsZGm7EOC6WCN+OTkxa8oy2d7LbZlPxR99Xm3TV5oorDOVvJ0q8CYgMxjrHrx oe052FvZqUGMto7bjySpV9JZN6jdRB2zFKOYn17c= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Giuliano Belinassi To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/autopar_devel] c++: Make braced-init-list as template arg work with aggr init [PR95369] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/devel/autopar_devel X-Git-Oldrev: 8154466362e85c8c65437719137839522dd81a97 X-Git-Newrev: 9beccc2271b099135542595f58db622e17be608b Message-Id: <20200822220742.A74C53850410@sourceware.org> Date: Sat, 22 Aug 2020 22:07:42 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Aug 2020 22:07:42 -0000 https://gcc.gnu.org/g:9beccc2271b099135542595f58db622e17be608b commit 9beccc2271b099135542595f58db622e17be608b Author: Marek Polacek Date: Fri Jun 5 14:22:35 2020 -0400 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 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. Diff: --- gcc/cp/call.c | 4 +++- gcc/testsuite/g++.dg/cpp2a/nontype-class38.C | 30 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 2b393f96e5b..3c97b9846e2 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 00000000000..5b440fd1c9e --- /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 +void fnc() +{ +} + +template struct X { }; +template 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; +}