diff options
author | Jason Merrill <jason@redhat.com> | 2024-08-05 11:21:05 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2024-08-06 13:04:23 -0400 |
commit | 4add6cd341a779e980e41ed6fb49175fca37496e (patch) | |
tree | 36f78c59bb39e198699e522020e6dc924572eb8a | |
parent | 352c21c8a22a48d34cbd2fbfe398ee12c0a1d681 (diff) | |
download | gcc-4add6cd341a779e980e41ed6fb49175fca37496e.zip gcc-4add6cd341a779e980e41ed6fb49175fca37496e.tar.gz gcc-4add6cd341a779e980e41ed6fb49175fca37496e.tar.bz2 |
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.
-rw-r--r-- | gcc/cp/pt.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/nontype-auto25.C | 18 |
2 files changed, 23 insertions, 1 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 35a9c56..cf65b34 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 0000000..36b38b4 --- /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); +} |