From b46e1a69975d64ad436ff1c928e008105b2b2a8d Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 13 Dec 2018 20:47:32 +0000 Subject: [PATCH] PR c++/88216 - ICE with class type in non-type template parameter. * mangle.c (write_expression): Handle TARGET_EXPR and VIEW_CONVERT_EXPR. * pt.c (convert_nontype_argument): Don't call get_template_parm_object for value-dependent expressions. * g++.dg/cpp2a/nontype-class9.C: New test. From-SVN: r267108 --- gcc/cp/ChangeLog | 8 ++++++ gcc/cp/mangle.c | 10 ++++++- gcc/cp/pt.c | 3 ++- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/cpp2a/nontype-class9.C | 29 +++++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 503bbbb7598..46557bec5c2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-12-13 Marek Polacek + + PR c++/88216 - ICE with class type in non-type template parameter. + * mangle.c (write_expression): Handle TARGET_EXPR and + VIEW_CONVERT_EXPR. + * pt.c (convert_nontype_argument): Don't call + get_template_parm_object for value-dependent expressions. + 2018-12-13 Nathan Sidwell PR c++/87531 diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 64415894bc5..56247883010 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -2836,13 +2836,21 @@ write_expression (tree expr) { enum tree_code code = TREE_CODE (expr); + if (TREE_CODE (expr) == TARGET_EXPR) + { + expr = TARGET_EXPR_INITIAL (expr); + code = TREE_CODE (expr); + } + /* Skip NOP_EXPR and CONVERT_EXPR. They can occur when (say) a pointer argument is converted (via qualification conversions) to another type. */ while (CONVERT_EXPR_CODE_P (code) || location_wrapper_p (expr) /* Parentheses aren't mangled. */ || code == PAREN_EXPR - || code == NON_LVALUE_EXPR) + || code == NON_LVALUE_EXPR + || (code == VIEW_CONVERT_EXPR + && TREE_CODE (TREE_OPERAND (expr, 0)) == TEMPLATE_PARM_INDEX)) { expr = TREE_OPERAND (expr, 0); code = TREE_CODE (expr); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 8560e588593..3b378ee9ff4 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7123,7 +7123,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) { /* Replace the argument with a reference to the corresponding template parameter object. */ - expr = get_template_parm_object (expr, complain); + if (!value_dependent_expression_p (expr)) + expr = get_template_parm_object (expr, complain); if (expr == error_mark_node) return NULL_TREE; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 19c82c17b46..a3076872723 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-12-13 Marek Polacek + + PR c++/88216 - ICE with class type in non-type template parameter. + * g++.dg/cpp2a/nontype-class9.C: New test. + 2018-12-13 Jakub Jelinek PR rtl-optimization/88416 diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class9.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class9.C new file mode 100644 index 00000000000..737f712be47 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class9.C @@ -0,0 +1,29 @@ +// PR c++/88216 +// { dg-do compile { target c++2a } } + +template struct same; +template struct same {}; + +struct T { }; + +template +struct U { }; + +template +void f (U) +{ + same s; + same s2; +} + +template +U u; + +T t; +U u2; + +void +g () +{ + f(u2); +} -- 2.30.2