aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2024-01-30 10:13:41 -0500
committerPatrick Palka <ppalka@redhat.com>2024-01-30 10:13:41 -0500
commitaf37bef86199e50368cbfbc97befe0622a07f12f (patch)
tree49da7d3efffe280f4a66990c607e706393a2d527 /gcc
parent5525dd754b84cef3afe43dc7fdf27664873f137b (diff)
downloadgcc-af37bef86199e50368cbfbc97befe0622a07f12f.zip
gcc-af37bef86199e50368cbfbc97befe0622a07f12f.tar.gz
gcc-af37bef86199e50368cbfbc97befe0622a07f12f.tar.bz2
c++: unifying integer parm with type-dep arg [PR113644]
Here when trying to unify P=42 A=T::value we ICE due to the latter's empty type, which same_type_p dislikes. 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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.cc3
-rw-r--r--gcc/testsuite/g++.dg/template/nontype30.C13
2 files changed, 15 insertions, 1 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index fb2448a..5871cb6 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -24949,7 +24949,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 0000000..926a772
--- /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" }
+}