gcc/PR-c-83227-C-17-ICE-with-init-list-derived.patch

82 lines
2.4 KiB
Diff

From ac9de5374b4e2f4aa45c0e4f720a9727b44ab534 Mon Sep 17 00:00:00 2001
From: LiYanCheng <412998149@qq.com>
Date: Sat, 20 Nov 2021 15:50:38 +0800
Subject: [PATCH] Backport PR c++/83227 - C++17 ICE with init-list
derived-to-base conversion.
---
gcc/cp/ChangeLog | 6 ++++++
gcc/cp/call.c | 9 +++++----
gcc/testsuite/g++.dg/cpp0x/initlist98.C | 17 +++++++++++++++++
3 files changed, 28 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist98.C
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b5d15c7b6..6aa0075b5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-02-15 Jason Merrill <jason@redhat.com>
+
+ PR c++/83227 - C++17 ICE with init-list derived-to-base conversion.
+ * call.c (convert_like_real): Don't use the copy-list-initialization
+ shortcut for ck_base.
+
2018-01-25 Release Manager
* GCC 7.3.0 released.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 56f6b9323..0993c2acf 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6886,6 +6886,11 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
&& DECL_INHERITED_CTOR (current_function_decl))
return expr;
+ if (TREE_CODE (expr) == TARGET_EXPR
+ && TARGET_EXPR_LIST_INIT_P (expr))
+ /* Copy-list-initialization doesn't actually involve a copy. */
+ return expr;
+
/* Fall through. */
case ck_base:
if (convs->kind == ck_base && !convs->need_temporary_p)
@@ -6911,10 +6916,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
flags |= LOOKUP_ONLYCONVERTING;
if (convs->rvaluedness_matches_p)
flags |= LOOKUP_PREFER_RVALUE;
- if (TREE_CODE (expr) == TARGET_EXPR
- && TARGET_EXPR_LIST_INIT_P (expr))
- /* Copy-list-initialization doesn't actually involve a copy. */
- return expr;
expr = build_temp (expr, totype, flags, &diag_kind, complain);
if (diag_kind && complain)
{
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist98.C b/gcc/testsuite/g++.dg/cpp0x/initlist98.C
new file mode 100644
index 000000000..4f2fcd202
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist98.C
@@ -0,0 +1,17 @@
+// PR c++/83227
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+
+template <typename d> struct f {
+ f(std::initializer_list<d>) {}
+};
+
+struct h {};
+struct i : h {
+ i();
+};
+void foo(f<h>);
+int main() {
+ foo({i{}});
+}
--
2.27.0