Tested x86_64-pc-linux-gnu, applying to trunk and 14. -- 8< --
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. --- gcc/cp/pt.cc | 6 +++++- gcc/testsuite/g++.dg/cpp1z/nontype-auto25.C | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/nontype-auto25.C 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 <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); +} base-commit: 352c21c8a22a48d34cbd2fbfe398ee12c0a1d681 -- 2.45.2