* [PATCH] c++: unifying INTEGER_CST parm with type-dep arg [PR113644]
@ 2024-01-29 20:53 Patrick Palka
2024-01-29 23:48 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2024-01-29 20:53 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?
-- >8 --
Here when trying to unify P=42 A=T::value we ICE due to the latter's
empty type, which same_type_p dislikes. If the argument has empty type
then it can't be an INTEGER_CST, so unification should fail.
PR c++/113644
gcc/cp/ChangeLog:
* pt.cc (unify) <case INTEGER_CST>: Handle NULL_TREE type.
gcc/testsuite/ChangeLog:
* g++.dg/template/nontype30.C: New test.
---
gcc/cp/pt.cc | 3 ++-
gcc/testsuite/g++.dg/template/nontype30.C | 13 +++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/template/nontype30.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 74013533b0f..0d8dbc68962 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -24953,7 +24953,8 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
/* Type INTEGER_CST can come from ordinary constant template args. */
case INTEGER_CST:
case REAL_CST:
- if (!same_type_p (TREE_TYPE (parm), TREE_TYPE (arg)))
+ if (TREE_TYPE (arg) == NULL_TREE
+ || !same_type_p (TREE_TYPE (parm), TREE_TYPE (arg)))
return unify_template_argument_mismatch (explain_p, parm, arg);
while (CONVERT_EXPR_P (arg))
arg = TREE_OPERAND (arg, 0);
diff --git a/gcc/testsuite/g++.dg/template/nontype30.C b/gcc/testsuite/g++.dg/template/nontype30.C
new file mode 100644
index 00000000000..926a7726547
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/nontype30.C
@@ -0,0 +1,13 @@
+// PR c++/113644
+
+template<int> struct A { };
+
+template<class T> void f(A<42>);
+template<class T> void f(A<T::value>);
+
+struct B { static const int value = 42; };
+
+int main() {
+ A<42> a;
+ f<B>(a); // { dg-error "ambiguous" }
+}
--
2.43.0.440.gb50a608ba2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: unifying INTEGER_CST parm with type-dep arg [PR113644]
2024-01-29 20:53 [PATCH] c++: unifying INTEGER_CST parm with type-dep arg [PR113644] Patrick Palka
@ 2024-01-29 23:48 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-01-29 23:48 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 1/29/24 15:53, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
> OK for trunk?
OK.
> -- >8 --
>
> Here when trying to unify P=42 A=T::value we ICE due to the latter's
> empty type, which same_type_p dislikes. If the argument has empty type
> then it can't be an INTEGER_CST, so unification should fail.
>
> PR c++/113644
>
> gcc/cp/ChangeLog:
>
> * pt.cc (unify) <case INTEGER_CST>: Handle NULL_TREE type.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/template/nontype30.C: New test.
> ---
> gcc/cp/pt.cc | 3 ++-
> gcc/testsuite/g++.dg/template/nontype30.C | 13 +++++++++++++
> 2 files changed, 15 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/template/nontype30.C
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 74013533b0f..0d8dbc68962 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -24953,7 +24953,8 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
> /* Type INTEGER_CST can come from ordinary constant template args. */
> case INTEGER_CST:
> case REAL_CST:
> - if (!same_type_p (TREE_TYPE (parm), TREE_TYPE (arg)))
> + if (TREE_TYPE (arg) == NULL_TREE
> + || !same_type_p (TREE_TYPE (parm), TREE_TYPE (arg)))
> return unify_template_argument_mismatch (explain_p, parm, arg);
> while (CONVERT_EXPR_P (arg))
> arg = TREE_OPERAND (arg, 0);
> diff --git a/gcc/testsuite/g++.dg/template/nontype30.C b/gcc/testsuite/g++.dg/template/nontype30.C
> new file mode 100644
> index 00000000000..926a7726547
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/nontype30.C
> @@ -0,0 +1,13 @@
> +// PR c++/113644
> +
> +template<int> struct A { };
> +
> +template<class T> void f(A<42>);
> +template<class T> void f(A<T::value>);
> +
> +struct B { static const int value = 42; };
> +
> +int main() {
> + A<42> a;
> + f<B>(a); // { dg-error "ambiguous" }
> +}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-29 23:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29 20:53 [PATCH] c++: unifying INTEGER_CST parm with type-dep arg [PR113644] Patrick Palka
2024-01-29 23:48 ` 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).