From fc39d4e18b473b923571614bfd6aed0707f8ac56 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 21 Jun 2019 20:32:06 +0000 Subject: [PATCH] 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: r272571 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/pt.c | 18 ++++++++++++------ gcc/testsuite/ChangeLog | 8 +++++++- gcc/testsuite/g++.dg/cpp0x/nondeduced1.C | 16 ++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/nondeduced2.C | 14 ++++++++++++++ gcc/testsuite/g++.dg/cpp0x/nondeduced3.C | 16 ++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/nondeduced4.C | 13 +++++++++++++ 7 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/nondeduced1.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/nondeduced2.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/nondeduced3.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/nondeduced4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bc4fda7..12da65e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 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. + PR c++/64235 - missing syntax error with invalid alignas. * parser.c (cp_parser_std_attribute_spec): Commit to tentative parse if there's a missing close paren. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2a62652..69de553 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -22786,7 +22786,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: @@ -22794,15 +22796,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/ChangeLog b/gcc/testsuite/ChangeLog index 44350ee..e80c422 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,10 @@ -2019-06-19 Marek Polacek +2019-06-21 Marek Polacek + + PR c++/60223 - ICE with T{} in 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. PR c++/64235 - missing syntax error with invalid alignas. * g++.dg/parse/alignas1.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/nondeduced1.C b/gcc/testsuite/g++.dg/cpp0x/nondeduced1.C new file mode 100644 index 0000000..067079e --- /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 0000000..3f96fe4 --- /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 0000000..d943dce --- /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 0000000..818034c --- /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()); +} -- 2.7.4