https://gcc.gnu.org/g:b1102f7c478136bfe18ceaf7db9572a8a757a3d2
commit r14-10570-gb1102f7c478136bfe18ceaf7db9572a8a757a3d2 Author: Jason Merrill <ja...@redhat.com> Date: Mon Aug 5 11:21:05 2024 -0400 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. (cherry picked from commit 4add6cd341a779e980e41ed6fb49175fca37496e) Diff: --- gcc/cp/pt.cc | 6 +++++- gcc/testsuite/g++.dg/cpp1z/nontype-auto25.C | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index ea4a6c9bf530..96a4f45909dd 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -23073,6 +23073,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); @@ -24602,7 +24604,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 000000000000..36b38b48ec2d --- /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 <int T> struct A { int value = T; }; + +template <unsigned char X> using B = A<X>; + +template <auto X> +void foo(B<X>& mat) noexcept +{ + // std::cout << mat.value << "\n"; +} + +int main() +{ + A<2> mat; + foo(mat); +}