[2/2] c++: more non-type template parms [PR116223]

Message ID 20240806170600.1194563-2-jason@redhat.com
State Committed
Commit b2a8ee0e5d8cfa92bafd0db4b03626b26ac21948
Headers
Series [1/2] c++: alias and non-type template parm [PR116223] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Jason Merrill Aug. 6, 2024, 5:05 p.m. UTC
  Tested x86_64-pc-linux-gnu, applying to trunk (not 14).

-- 8< --

Building on the last patch, deduction should probably look through all
IMPLICIT_CONV_EXPR like we do other conversions.

One resulting regression turned out to be due to PR94568, fixed separately.

The one other regression was for a seeming mismatch between a function and
its address, handled here.  Before this change we treated the
IMPLICIT_CONV_EXPR as dependent because the template parameter has dependent
type.

	PR c++/116223

gcc/cp/ChangeLog:

	* pt.cc (deducible_expression): Strip all IMPLICIT_CONV_EXPR.
	(unify): Likewise.  Handle resulting function/addr mismatch.
---
 gcc/cp/pt.cc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
  

Patch

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index cf65b347f6c..677ed7d1289 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -23031,8 +23031,7 @@  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))
+	 || TREE_CODE (expr) == IMPLICIT_CONV_EXPR
 	 || REFERENCE_REF_P (expr))
     expr = TREE_OPERAND (expr, 0);
   return (TREE_CODE (expr) == TEMPLATE_PARM_INDEX);
@@ -24563,8 +24562,7 @@  unify (tree tparms, tree targs, tree parm, tree arg, int strict,
      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
-	 || (TREE_CODE (parm) == IMPLICIT_CONV_EXPR
-	     && IMPLICIT_CONV_EXPR_FORCED (parm)))
+	 || TREE_CODE (parm) == IMPLICIT_CONV_EXPR)
     parm = TREE_OPERAND (parm, 0);
 
   if (arg == error_mark_node)
@@ -24578,6 +24576,12 @@  unify (tree tparms, tree targs, tree parm, tree arg, int strict,
   if (parm == any_targ_node || arg == any_targ_node)
     return unify_success (explain_p);
 
+  /* Stripping IMPLICIT_CONV_EXPR above can produce this mismatch
+     (g++.dg/abi/mangle57.C).  */
+  if (TREE_CODE (parm) == FUNCTION_DECL
+      && TREE_CODE (arg) == ADDR_EXPR)
+    arg = TREE_OPERAND (arg, 0);
+
   /* If PARM uses template parameters, then we can't bail out here,
      even if ARG == PARM, since we won't record unifications for the
      template parameters.  We might need them if we're trying to