From: Patrick Palka Date: Wed, 26 Jul 2023 20:52:13 +0000 (-0400) Subject: c++: unifying REAL_CSTs [PR110809] X-Git-Tag: basepoints/gcc-15~7333 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=744e1f35266dbd6b6fb95c7e8422562815f8b56f;p=thirdparty%2Fgcc.git c++: unifying REAL_CSTs [PR110809] This teaches unify how to compare two REAL_CSTs. PR c++/110809 gcc/cp/ChangeLog: * pt.cc (unify) : Generalize to handle REAL_CST as well. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-float3.C: New test. --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 265e2a59a527..43818ba925fa 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -24914,12 +24914,13 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, /* Types INTEGER_CST and MINUS_EXPR can come from array bounds. */ /* Type INTEGER_CST can come from ordinary constant template args. */ case INTEGER_CST: + case REAL_CST: while (CONVERT_EXPR_P (arg)) arg = TREE_OPERAND (arg, 0); - if (TREE_CODE (arg) != INTEGER_CST) + if (TREE_CODE (arg) != TREE_CODE (parm)) return unify_template_argument_mismatch (explain_p, parm, arg); - return (tree_int_cst_equal (parm, arg) + return (simple_cst_equal (parm, arg) ? unify_success (explain_p) : unify_template_argument_mismatch (explain_p, parm, arg)); diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-float3.C b/gcc/testsuite/g++.dg/cpp2a/nontype-float3.C new file mode 100644 index 000000000000..044fb99905a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-float3.C @@ -0,0 +1,12 @@ +// PR c++/110809 +// { dg-do compile { target c++20 } } + +template struct A { }; + +template void f(A); +template void f(A); + +int main() { + f(A{}); + f(A{}); // { dg-error "no match" } +}