From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] c++: unifying equal NONTYPE_ARGUMENT_PACKs [PR102547]
Date: Fri, 1 Oct 2021 09:46:43 -0400 [thread overview]
Message-ID: <20211001134643.1941700-1-ppalka@redhat.com> (raw)
Here during partial ordering of the two partial specializations we end
up in unify with parm=arg=NONTYPE_ARGUMENT_PACK<V0, V1>, and crash shortly
thereafter because uses_template_parms calls potential_constant_expression
which doesn't handle NONTYPE_ARGUMENT_PACK.
This patch fixes this by checking dependent_template_arg_p instead of
uses_template_parms when parm==arg, which does handle NONTYPE_ARGUMENT_PACK.
We could also perhaps fix uses_template_parms / inst_dep_expr_p to better
handle NONTYPE_ARGUMENT_PACK, but interestingly none of our existing tests
exercise calling those functions on NONTYPE_ARGUMENT_PACK, so such a fix
would be seemingly moot.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/11?
PR c++/102547
gcc/cp/ChangeLog:
* pt.c (unify): Check dependent_template_arg_p instead of
uses_template_parms when parm==arg.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/variadic-partial2.C: New test.
---
gcc/cp/pt.c | 2 +-
.../g++.dg/cpp0x/variadic-partial2.C | 16 ++++++++++++++
.../g++.dg/cpp0x/variadic-partial2a.C | 22 +++++++++++++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/variadic-partial2.C
create mode 100644 gcc/testsuite/g++.dg/cpp0x/variadic-partial2a.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1dcdffe322a..59c00c77a30 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -23587,7 +23587,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
even if ARG == PARM, since we won't record unifications for the
template parameters. We might need them if we're trying to
figure out which of two things is more specialized. */
- if (arg == parm && !uses_template_parms (parm))
+ if (arg == parm && !dependent_template_arg_p (parm))
return unify_success (explain_p);
/* Handle init lists early, so the rest of the function can assume
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic-partial2.C b/gcc/testsuite/g++.dg/cpp0x/variadic-partial2.C
new file mode 100644
index 00000000000..df61f26a3c1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic-partial2.C
@@ -0,0 +1,16 @@
+// PR c++/102547
+// { dg-do compile { target c++11 } }
+
+template<int... Vs>
+struct vals { };
+
+template<class V, class T>
+struct vals_client { };
+
+template<int V0, int V1, class T>
+struct vals_client<vals<V0, V1>, T> { };
+
+template<int V0, int V1>
+struct vals_client<vals<V0, V1>, void> { };
+
+template struct vals_client<vals<1, 2>, void>; //- "sorry, unimplemented..., ICE"
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic-partial2a.C b/gcc/testsuite/g++.dg/cpp0x/variadic-partial2a.C
new file mode 100644
index 00000000000..cc0ea488ad3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic-partial2a.C
@@ -0,0 +1,22 @@
+// PR c++/102547
+// { dg-do compile { target c++11 } }
+// A version of variadic-partial2.C where the partial ordering is performed
+// on function templates instead of class templates.
+
+template<int... Vs>
+struct vals { };
+
+template<class V, class T>
+void f(V, T) { };
+
+template<int V0, int V1, class T>
+void f(vals<V0, V1>, T) { };
+
+template<int V0, int V1>
+void f(vals<V0, V1>, char) { };
+
+template void f(vals<1, 2>, char); //- "sorry, unimplemented..., ICE"
+
+int main() {
+ f(vals<1, 3>{}, 'a'); //- "sorry, unimplemented..., ICE"
+}
--
2.33.0.610.gcefe983a32
next reply other threads:[~2021-10-01 13:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-01 13:46 Patrick Palka [this message]
2021-10-01 13:57 ` Jason Merrill
2021-10-01 14:26 ` Patrick Palka
2021-10-01 15:36 ` Jason Merrill
2021-10-01 17:29 ` Patrick Palka
2021-10-02 0:22 ` Patrick Palka
2021-10-02 0:39 ` Patrick Palka
2021-10-05 18:55 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211001134643.1941700-1-ppalka@redhat.com \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).