public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: unifying REAL_CSTs [PR110809]
@ 2023-07-26 16:57 Patrick Palka
  2023-07-26 17:00 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-07-26 16:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/13 (after the branch is unfrozen)?

-- >8 --

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                                |  5 +++--
 gcc/testsuite/g++.dg/cpp2a/nontype-float3.C | 12 ++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-float3.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index d342ab5929a..1e09f304490 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -24890,12 +24890,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 00000000000..044fb99905a
--- /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<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" }
+}
-- 
2.41.0.450.ga80be15292


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: unifying REAL_CSTs [PR110809]
  2023-07-26 16:57 [PATCH] c++: unifying REAL_CSTs [PR110809] Patrick Palka
@ 2023-07-26 17:00 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-07-26 17:00 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 7/26/23 12:57, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/13 (after the branch is unfrozen)?

OK.

> -- >8 --
> 
> 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                                |  5 +++--
>   gcc/testsuite/g++.dg/cpp2a/nontype-float3.C | 12 ++++++++++++
>   2 files changed, 15 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-float3.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index d342ab5929a..1e09f304490 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -24890,12 +24890,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 00000000000..044fb99905a
> --- /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<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" }
> +}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-26 17:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26 16:57 [PATCH] c++: unifying REAL_CSTs [PR110809] Patrick Palka
2023-07-26 17:00 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).