From: Jason Merrill Date: Mon, 5 Aug 2024 15:21:05 +0000 (-0400) Subject: c++: alias and non-type template parm [PR116223] X-Git-Tag: basepoints/gcc-16~6793 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4add6cd341a779e980e41ed6fb49175fca37496e;p=thirdparty%2Fgcc.git c++: alias and non-type template parm [PR116223] My r14-8291 for PR112632 introduced IMPLICIT_CONV_EXPR_FORCED to express conversions to the type of an alias template parameter. In this example, that broke deduction of X in the call to foo, so let's teach deduction to look through it. PR c++/116223 PR c++/112632 gcc/cp/ChangeLog: * pt.cc (deducible_expression): Also look through IMPLICIT_CONV_EXPR_FORCED. (unify): Likewise. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/nontype-auto25.C: New test. --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 35a9c5619f9..cf65b347f6c 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -23031,6 +23031,8 @@ deducible_expression (tree expr) /* Strip implicit conversions and implicit INDIRECT_REFs. */ while (CONVERT_EXPR_P (expr) || TREE_CODE (expr) == VIEW_CONVERT_EXPR + || (TREE_CODE (expr) == IMPLICIT_CONV_EXPR + && IMPLICIT_CONV_EXPR_FORCED (expr)) || REFERENCE_REF_P (expr)) expr = TREE_OPERAND (expr, 0); return (TREE_CODE (expr) == TEMPLATE_PARM_INDEX); @@ -24560,7 +24562,9 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, signedness is the only information lost, and I think that will be okay. VIEW_CONVERT_EXPR can appear with class NTTP, thanks to finish_id_expression_1, and are also OK. */ - while (CONVERT_EXPR_P (parm) || TREE_CODE (parm) == VIEW_CONVERT_EXPR) + while (CONVERT_EXPR_P (parm) || TREE_CODE (parm) == VIEW_CONVERT_EXPR + || (TREE_CODE (parm) == IMPLICIT_CONV_EXPR + && IMPLICIT_CONV_EXPR_FORCED (parm))) parm = TREE_OPERAND (parm, 0); if (arg == error_mark_node) diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype-auto25.C b/gcc/testsuite/g++.dg/cpp1z/nontype-auto25.C new file mode 100644 index 00000000000..36b38b48ec2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/nontype-auto25.C @@ -0,0 +1,18 @@ +// PR c++/116223 +// { dg-do compile { target c++17 } } + +template struct A { int value = T; }; + +template using B = A; + +template +void foo(B& mat) noexcept +{ + // std::cout << mat.value << "\n"; +} + +int main() +{ + A<2> mat; + foo(mat); +}