* [PATCH] c++: ICE during constrained template friend matching [PR105064]
@ 2022-03-28 13:29 Patrick Palka
2022-03-28 17:31 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-03-28 13:29 UTC (permalink / raw)
To: gcc-patches
Here during declaration matching for the two constrained template
friends, we crash from maybe_substitute_reqs_for because the second
friend doesn't yet have DECL_TEMPLATE_INFO set (we're being called
indirectly from push_template_decl).
As far as I can tell, this situation happens only when declaring a
constrained template friend within a non-template class (as in the
testcase), in which case the substitution would be a no-op anyway, so it
should be safe to just skip it. To that end this patch rearranges
maybe_substitute_reqs_for to gracefully handle DECL_TEMPLATE_INFO being
empty.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/11?
PR c++/105064
gcc/cp/ChangeLog:
* constraint.cc (maybe_substitute_reqs_for): Don't assume
DECL_TEMPLATE_INFO is set.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-friend9.C: New test.
---
gcc/cp/constraint.cc | 13 ++++---------
gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C | 12 ++++++++++++
2 files changed, 16 insertions(+), 9 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index e14578b1721..c5a991b9e71 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -1268,20 +1268,15 @@ remove_constraints (tree t)
for declaration matching. */
tree
-maybe_substitute_reqs_for (tree reqs, const_tree decl_)
+maybe_substitute_reqs_for (tree reqs, const_tree decl)
{
if (reqs == NULL_TREE)
return NULL_TREE;
- tree decl = CONST_CAST_TREE (decl_);
- tree result = STRIP_TEMPLATE (decl);
-
- if (DECL_UNIQUE_FRIEND_P (result))
+ decl = STRIP_TEMPLATE (decl);
+ if (DECL_UNIQUE_FRIEND_P (decl) && DECL_TEMPLATE_INFO (decl))
{
- tree tmpl = decl;
- if (TREE_CODE (decl) != TEMPLATE_DECL)
- tmpl = DECL_TI_TEMPLATE (result);
-
+ tree tmpl = DECL_TI_TEMPLATE (decl);
tree gargs = generic_targs_for (tmpl);
processing_template_decl_sentinel s;
if (uses_template_parms (gargs))
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C b/gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C
new file mode 100644
index 00000000000..09054d23d5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C
@@ -0,0 +1,12 @@
+// PR c++/105064
+// { dg-do compile { target c++20 } }
+
+struct A {
+ template<class T>
+ friend void f(T) requires true;
+};
+
+struct B {
+ template<class T>
+ friend void f(T) requires true;
+};
--
2.35.1.677.gabf474a5dd
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: ICE during constrained template friend matching [PR105064]
2022-03-28 13:29 [PATCH] c++: ICE during constrained template friend matching [PR105064] Patrick Palka
@ 2022-03-28 17:31 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-03-28 17:31 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 3/28/22 09:29, Patrick Palka wrote:
> Here during declaration matching for the two constrained template
> friends, we crash from maybe_substitute_reqs_for because the second
> friend doesn't yet have DECL_TEMPLATE_INFO set (we're being called
> indirectly from push_template_decl).
>
> As far as I can tell, this situation happens only when declaring a
> constrained template friend within a non-template class (as in the
> testcase), in which case the substitution would be a no-op anyway, so it
> should be safe to just skip it. To that end this patch rearranges
> maybe_substitute_reqs_for to gracefully handle DECL_TEMPLATE_INFO being
> empty.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/11?
OK.
> PR c++/105064
>
> gcc/cp/ChangeLog:
>
> * constraint.cc (maybe_substitute_reqs_for): Don't assume
> DECL_TEMPLATE_INFO is set.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp2a/concepts-friend9.C: New test.
> ---
> gcc/cp/constraint.cc | 13 ++++---------
> gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C | 12 ++++++++++++
> 2 files changed, 16 insertions(+), 9 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C
>
> diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
> index e14578b1721..c5a991b9e71 100644
> --- a/gcc/cp/constraint.cc
> +++ b/gcc/cp/constraint.cc
> @@ -1268,20 +1268,15 @@ remove_constraints (tree t)
> for declaration matching. */
>
> tree
> -maybe_substitute_reqs_for (tree reqs, const_tree decl_)
> +maybe_substitute_reqs_for (tree reqs, const_tree decl)
> {
> if (reqs == NULL_TREE)
> return NULL_TREE;
>
> - tree decl = CONST_CAST_TREE (decl_);
> - tree result = STRIP_TEMPLATE (decl);
> -
> - if (DECL_UNIQUE_FRIEND_P (result))
> + decl = STRIP_TEMPLATE (decl);
> + if (DECL_UNIQUE_FRIEND_P (decl) && DECL_TEMPLATE_INFO (decl))
> {
> - tree tmpl = decl;
> - if (TREE_CODE (decl) != TEMPLATE_DECL)
> - tmpl = DECL_TI_TEMPLATE (result);
> + tree tmpl = DECL_TI_TEMPLATE (decl);
> tree gargs = generic_targs_for (tmpl);
> processing_template_decl_sentinel s;
> if (uses_template_parms (gargs))
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C b/gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C
> new file mode 100644
> index 00000000000..09054d23d5d
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-friend9.C
> @@ -0,0 +1,12 @@
> +// PR c++/105064
> +// { dg-do compile { target c++20 } }
> +
> +struct A {
> + template<class T>
> + friend void f(T) requires true;
> +};
> +
> +struct B {
> + template<class T>
> + friend void f(T) requires true;
> +};
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-28 17:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-28 13:29 [PATCH] c++: ICE during constrained template friend matching [PR105064] Patrick Palka
2022-03-28 17:31 ` 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).