]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: unifying REAL_CSTs [PR110809]
authorPatrick Palka <ppalka@redhat.com>
Wed, 26 Jul 2023 20:52:13 +0000 (16:52 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 26 Jul 2023 20:52:13 +0000 (16:52 -0400)
This teaches unify how to compare two REAL_CSTs.

PR c++/110809

gcc/cp/ChangeLog:

* pt.cc (unify) <case INTEGER_CST>: Generalize to handle
REAL_CST as well.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/nontype-float3.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/nontype-float3.C [new file with mode: 0644]

index 265e2a59a52700d6dd401b9d2f6181e1cfe99322..43818ba925faeceef93c76259cf0747409735b5b 100644 (file)
@@ -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 (file)
index 0000000..044fb99
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/110809
+// { dg-do compile { target c++20 } }
+
+template<class, double> struct A { };
+
+template<class T> void f(A<T, 1.0>);
+template<class T> void f(A<T, 2.0>);
+
+int main() {
+  f(A<int, 1.0>{});
+  f(A<int, 1.1>{}); // { dg-error "no match" }
+}