* [PATCH] c++: Remove superflous assert [PR104403]
@ 2022-02-08 8:16 Jakub Jelinek
2022-02-08 19:13 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-02-08 8:16 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
I've added the assert because start_decl diagnoses such vars for C++20 and
earlier:
if (current_function_decl && VAR_P (decl)
&& DECL_DECLARED_CONSTEXPR_P (current_function_decl)
&& cxx_dialect < cxx23)
but as can be seen, we cam trigger the assert in older standards e.g. during
non-manifestly constant evaluation. Rather than refining the assert that
DECL_EXPRs for such vars don't appear for C++20 and older if they are inside
of functions declared constexpr this patch just removes the assert, the
code rejects encountering those vars in constant expressions anyway.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2022-02-08 Jakub Jelinek <jakub@redhat.com>
PR c++/104403
* constexpr.cc (cxx_eval_constant_expression): Don't assert DECL_EXPRs
of TREE_STATIC vars may only appear in -std=c++23.
* g++.dg/cpp0x/lambda/lambda-104403.C: New test.
--- gcc/cp/constexpr.cc.jj 2022-02-06 11:16:22.353814431 +0100
+++ gcc/cp/constexpr.cc 2022-02-07 11:38:59.131165171 +0100
@@ -6652,7 +6652,6 @@ cxx_eval_constant_expression (const cons
/* Allow __FUNCTION__ etc. */
&& !DECL_ARTIFICIAL (r))
{
- gcc_assert (cxx_dialect >= cxx23);
if (!ctx->quiet)
{
if (CP_DECL_THREAD_LOCAL_P (r))
--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-104403.C.jj 2022-02-07 11:40:32.760847269 +0100
+++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-104403.C 2022-02-07 11:40:06.109223079 +0100
@@ -0,0 +1,8 @@
+// PR c++/104403
+// { dg-do compile { target c++11 } }
+
+int
+main ()
+{
+ []{ switch (0) { case 0: static int value; return &value; } };
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Remove superflous assert [PR104403]
2022-02-08 8:16 [PATCH] c++: Remove superflous assert [PR104403] Jakub Jelinek
@ 2022-02-08 19:13 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-02-08 19:13 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 2/8/22 03:16, Jakub Jelinek wrote:
> Hi!
>
> I've added the assert because start_decl diagnoses such vars for C++20 and
> earlier:
> if (current_function_decl && VAR_P (decl)
> && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
> && cxx_dialect < cxx23)
> but as can be seen, we cam trigger the assert in older standards e.g. during
> non-manifestly constant evaluation. Rather than refining the assert that
> DECL_EXPRs for such vars don't appear for C++20 and older if they are inside
> of functions declared constexpr this patch just removes the assert, the
> code rejects encountering those vars in constant expressions anyway.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 2022-02-08 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/104403
> * constexpr.cc (cxx_eval_constant_expression): Don't assert DECL_EXPRs
> of TREE_STATIC vars may only appear in -std=c++23.
>
> * g++.dg/cpp0x/lambda/lambda-104403.C: New test.
>
> --- gcc/cp/constexpr.cc.jj 2022-02-06 11:16:22.353814431 +0100
> +++ gcc/cp/constexpr.cc 2022-02-07 11:38:59.131165171 +0100
> @@ -6652,7 +6652,6 @@ cxx_eval_constant_expression (const cons
> /* Allow __FUNCTION__ etc. */
> && !DECL_ARTIFICIAL (r))
> {
> - gcc_assert (cxx_dialect >= cxx23);
> if (!ctx->quiet)
> {
> if (CP_DECL_THREAD_LOCAL_P (r))
> --- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-104403.C.jj 2022-02-07 11:40:32.760847269 +0100
> +++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-104403.C 2022-02-07 11:40:06.109223079 +0100
> @@ -0,0 +1,8 @@
> +// PR c++/104403
> +// { dg-do compile { target c++11 } }
> +
> +int
> +main ()
> +{
> + []{ switch (0) { case 0: static int value; return &value; } };
> +}
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-08 19:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 8:16 [PATCH] c++: Remove superflous assert [PR104403] Jakub Jelinek
2022-02-08 19:13 ` 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).