* [PATCH] c++: Don't recurse on DECL_INITIAL for DECL_EXPR on non-VAR_DECLs [PR108606]
@ 2023-02-22 9:06 Jakub Jelinek
2023-02-28 16:11 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-02-22 9:06 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
The r13-2965-g73d9b0e5947e16 change changed the line touched in this patch
from
return RECUR (tmp, want_rval);
to
return RECUR (DECL_INITIAL (tmp), want_rval);
This is on DECL_EXPR handling code, where tmp can be lots of different
trees and DECL_INITIAL unfortunately also means different things on
different trees.
It is the initializer on VAR_DECL, DECL_ARG_TYPE on PARM_DECLs (though
those are unlikely to have DECL_EXPRs), for FUNCTION_DECLs the body,
..., USING_DECL_DECLS on USING_DECLs and DECL_FRIENDLIST on TYPE_DECLs.
The testcase below ICEs because we have a DECL_EXPR for TYPE_DECL
which has non-NULL DECL_FRIENDLIST and we certainly can't recurse on
the friend list.
The following patch is a conditional partial reversion of r13-2965,
it will recurse on DECL_INITIAL only for VAR_DECLs and for anything
else keep previous behavior.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2023-02-22 Jakub Jelinek <jakub@redhat.com>
PR c++/108606
* constexpr.cc (potential_constant_expression_1) <case DECL_EXPR>:
Only recurse on DECL_INITIAL (tmp) if tmp is a VAR_DECL, otherwise
recurse on tmp.
* g++.dg/cpp1y/pr108606.C: New test.
--- gcc/cp/constexpr.cc.jj 2023-02-20 22:06:36.000000000 +0100
+++ gcc/cp/constexpr.cc 2023-02-21 14:40:39.366910531 +0100
@@ -9699,7 +9699,9 @@ potential_constant_expression_1 (tree t,
(tmp, /*constexpr_context_p=*/true, flags))
return false;
}
- return RECUR (DECL_INITIAL (tmp), want_rval);
+ if (VAR_P (tmp))
+ return RECUR (DECL_INITIAL (tmp), want_rval);
+ return RECUR (tmp, want_rval);
case TRY_FINALLY_EXPR:
return (RECUR (TREE_OPERAND (t, 0), want_rval)
--- gcc/testsuite/g++.dg/cpp1y/pr108606.C.jj 2023-02-21 14:44:41.292380973 +0100
+++ gcc/testsuite/g++.dg/cpp1y/pr108606.C 2023-02-21 14:44:15.622755459 +0100
@@ -0,0 +1,11 @@
+// PR c++/108606
+// { dg-do compile { target c++14 } }
+
+template <typename T>
+void bar (T) {}
+
+void
+foo ()
+{
+ bar ([&] (auto x) { class C { friend void baz (); }; });
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Don't recurse on DECL_INITIAL for DECL_EXPR on non-VAR_DECLs [PR108606]
2023-02-22 9:06 [PATCH] c++: Don't recurse on DECL_INITIAL for DECL_EXPR on non-VAR_DECLs [PR108606] Jakub Jelinek
@ 2023-02-28 16:11 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-02-28 16:11 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 2/22/23 04:06, Jakub Jelinek wrote:
> Hi!
>
> The r13-2965-g73d9b0e5947e16 change changed the line touched in this patch
> from
> return RECUR (tmp, want_rval);
> to
> return RECUR (DECL_INITIAL (tmp), want_rval);
> This is on DECL_EXPR handling code, where tmp can be lots of different
> trees and DECL_INITIAL unfortunately also means different things on
> different trees.
> It is the initializer on VAR_DECL, DECL_ARG_TYPE on PARM_DECLs (though
> those are unlikely to have DECL_EXPRs), for FUNCTION_DECLs the body,
> ..., USING_DECL_DECLS on USING_DECLs and DECL_FRIENDLIST on TYPE_DECLs.
>
> The testcase below ICEs because we have a DECL_EXPR for TYPE_DECL
> which has non-NULL DECL_FRIENDLIST and we certainly can't recurse on
> the friend list.
>
> The following patch is a conditional partial reversion of r13-2965,
> it will recurse on DECL_INITIAL only for VAR_DECLs and for anything
> else keep previous behavior.
Hmm, we can probably just return true for non-VAR_DECLs. OK either way.
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2023-02-22 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/108606
> * constexpr.cc (potential_constant_expression_1) <case DECL_EXPR>:
> Only recurse on DECL_INITIAL (tmp) if tmp is a VAR_DECL, otherwise
> recurse on tmp.
>
> * g++.dg/cpp1y/pr108606.C: New test.
>
> --- gcc/cp/constexpr.cc.jj 2023-02-20 22:06:36.000000000 +0100
> +++ gcc/cp/constexpr.cc 2023-02-21 14:40:39.366910531 +0100
> @@ -9699,7 +9699,9 @@ potential_constant_expression_1 (tree t,
> (tmp, /*constexpr_context_p=*/true, flags))
> return false;
> }
> - return RECUR (DECL_INITIAL (tmp), want_rval);
> + if (VAR_P (tmp))
> + return RECUR (DECL_INITIAL (tmp), want_rval);
> + return RECUR (tmp, want_rval);
>
> case TRY_FINALLY_EXPR:
> return (RECUR (TREE_OPERAND (t, 0), want_rval)
> --- gcc/testsuite/g++.dg/cpp1y/pr108606.C.jj 2023-02-21 14:44:41.292380973 +0100
> +++ gcc/testsuite/g++.dg/cpp1y/pr108606.C 2023-02-21 14:44:15.622755459 +0100
> @@ -0,0 +1,11 @@
> +// PR c++/108606
> +// { dg-do compile { target c++14 } }
> +
> +template <typename T>
> +void bar (T) {}
> +
> +void
> +foo ()
> +{
> + bar ([&] (auto x) { class C { friend void baz (); }; });
> +}
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-28 16:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-22 9:06 [PATCH] c++: Don't recurse on DECL_INITIAL for DECL_EXPR on non-VAR_DECLs [PR108606] Jakub Jelinek
2023-02-28 16:11 ` 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).