summaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2020-04-18 06:22:21 -0400
committerPatrick Palka <ppalka@redhat.com>2020-04-18 06:23:10 -0400
commitf83adb68ed9cef1fbd4c16447eb4e89676df9f62 (patch)
tree97bb61c32c64d9d0a95801581efccfae9a5b7831 /gcc/testsuite
parente43b28ae7f09c0b7a30ab0dd976db761eeb1b0f9 (diff)
downloadgcc-f83adb68ed9cef1fbd4c16447eb4e89676df9f62.tar.gz
c++: spec_hasher::equal and PARM_DECLs [PR94632]
In the testcase below, during specialization of c<int>::d, we build two identical specializations of the parameter type b<decltype(e)::k> -- one when substituting into c<int>::d's TYPE_ARG_TYPES and another when substituting into c<int>::d's DECL_ARGUMENTS. We don't reuse the first specialization the second time around as a consequence of the fix for PR c++/56247 which made PARM_DECLs always compare different from one another during spec_hasher::equal. As a result, when looking up existing specializations of 'b', spec_hasher::equal considers the template argument decltype(e')::k to be different from decltype(e'')::k, where e' and e'' are the result of two calls to tsubst_copy on the PARM_DECL e. Since the two specializations are considered different due to the mentioned fix, their TYPE_CANONICAL points to themselves even though they are otherwise identical types, and this triggers an ICE in maybe_rebuild_function_decl_type when comparing the TYPE_ARG_TYPES of c<int>::d to its DECL_ARGUMENTS. This patch fixes this issue at the spec_hasher::equal level by ignoring the 'comparing_specializations' flag in cp_tree_equal whenever the DECL_CONTEXTs of the two parameters are identical. This seems to be a sufficient condition to be able to correctly compare PARM_DECLs structurally. (This also subsumes the CONSTRAINT_VAR_P check since constraint variables all have empty, and therefore identical, DECL_CONTEXTs.) gcc/cp/ChangeLog: PR c++/94632 * tree.c (cp_tree_equal) <case PARM_DECL>: Ignore comparing_specializations if the parameters' contexts are identical. gcc/testsuite/ChangeLog: PR c++/94632 * g++.dg/template/canon-type-14.C: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/template/canon-type-14.C8
2 files changed, 11 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 08bef53e911..a41cc03f6fa 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
2020-04-18 Patrick Palka <ppalka@redhat.com>
+ PR c++/94632
+ * g++.dg/template/canon-type-14.C: New test.
+
PR c++/92187
* g++.dg/concepts/abbrev5.C: New test.
* g++.dg/concepts/abbrev6.C: New test.
diff --git a/gcc/testsuite/g++.dg/template/canon-type-14.C b/gcc/testsuite/g++.dg/template/canon-type-14.C
new file mode 100644
index 00000000000..fa05bdb9a74
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/canon-type-14.C
@@ -0,0 +1,8 @@
+// PR c++/94632
+// { dg-do compile { target c++11 } }
+
+template <bool> struct b;
+template <typename> class c {
+ template <typename f> static void d(f e, b<decltype(e)::k>);
+};
+template class c<int>;