From: Marek Polacek Date: Tue, 2 Jul 2019 00:22:37 +0000 (+0000) Subject: PR c++/60223 - ICE with T{} in non-deduced context. X-Git-Tag: releases/gcc-9.2.0~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b966ac81e09c04a33fdc496f8313204c530fe7d;p=thirdparty%2Fgcc.git PR c++/60223 - ICE with T{} in non-deduced context. * pt.c (unify): Allow COMPOUND_LITERAL_P in a non-deduced context. * g++.dg/cpp0x/nondeduced1.C: New test. * g++.dg/cpp0x/nondeduced2.C: New test. * g++.dg/cpp0x/nondeduced3.C: New test. * g++.dg/cpp0x/nondeduced4.C: New test. From-SVN: r272917 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fa0f93768ab4..50e187be21a9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2019-07-01 Marek Polacek + + Backported from mainline + 2019-06-21 Marek Polacek + + PR c++/60223 - ICE with T{} in non-deduced context. + * pt.c (unify): Allow COMPOUND_LITERAL_P in a non-deduced context. + 2019-06-29 Jakub Jelinek Backported from mainline diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 9b5e6576b7e1..426700a7211b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22795,7 +22795,9 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, /* An unresolved overload is a nondeduced context. */ if (is_overloaded_fn (parm) || type_unknown_p (parm)) return unify_success (explain_p); - gcc_assert (EXPR_P (parm) || TREE_CODE (parm) == TRAIT_EXPR); + gcc_assert (EXPR_P (parm) + || COMPOUND_LITERAL_P (parm) + || TREE_CODE (parm) == TRAIT_EXPR); expr: /* We must be looking at an expression. This can happen with something like: @@ -22803,15 +22805,19 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, template void foo(S, S); - This is a "nondeduced context": + or + + template + void foo(A); + + This is a "non-deduced context": [deduct.type] - The nondeduced contexts are: + The non-deduced contexts are: - --A type that is a template-id in which one or more of - the template-arguments is an expression that references - a template-parameter. + --A non-type template argument or an array bound in which + a subexpression references a template parameter. In these cases, we assume deduction succeeded, but don't actually infer any unifications. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/nondeduced1.C b/gcc/testsuite/g++.dg/cpp0x/nondeduced1.C new file mode 100644 index 000000000000..067079e50df3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nondeduced1.C @@ -0,0 +1,16 @@ +// PR c++/60223 +// { dg-do compile { target c++11 } } + +template +struct A { }; + +template +void foo(A a); + +void bar() +{ + foo(A()); + foo(A()); + foo<>(A()); + foo<>(A()); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/nondeduced2.C b/gcc/testsuite/g++.dg/cpp0x/nondeduced2.C new file mode 100644 index 000000000000..3f96fe4e8588 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nondeduced2.C @@ -0,0 +1,14 @@ +// PR c++/60223 +// { dg-do compile { target c++11 } } + +template +struct A { }; + +template +void foo(A); + +void bar() +{ + foo(A()); + foo<>(A()); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/nondeduced3.C b/gcc/testsuite/g++.dg/cpp0x/nondeduced3.C new file mode 100644 index 000000000000..d943dceea4b0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nondeduced3.C @@ -0,0 +1,16 @@ +// PR c++/60223 +// { dg-do compile { target c++11 } } + +template +struct A { }; + +template +void foo(A a); + +void bar() +{ + foo(A()); + foo(A()); + foo<>(A()); + foo<>(A()); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/nondeduced4.C b/gcc/testsuite/g++.dg/cpp0x/nondeduced4.C new file mode 100644 index 000000000000..818034c857c9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nondeduced4.C @@ -0,0 +1,13 @@ +// PR c++/60223 +// { dg-do compile { target c++11 } } + +template +struct A { }; + +template +void foo(A, T = T{}); + +void bar() +{ + foo(A()); +}