From f7c24445e812fb0ebf1aee4d27ab5d3b18996b6f Mon Sep 17 00:00:00 2001 From: Matthew Horsfall Date: Fri, 14 Nov 2025 18:12:07 -0500 Subject: [PATCH] Don't warn about jumping into a construct if we're DIE-ing There are many cases where we throw exceptions if you attempt to goto somewhere you have no business going. We'd *also* throw a deprecation warning in these cases, which just seems silly. Deprecated means "this will stop working eventually", so there's no need to throw that when we're just going to die right now. --- pp_ctl.c | 11 ++++++++--- t/lib/croak/pp_ctl | 9 +++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pp_ctl.c b/pp_ctl.c index 6516005c83..04f66a7b6f 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -3250,6 +3250,7 @@ PP(pp_goto) I32 ix; PERL_CONTEXT *cx; OP *enterops[GOTO_DEPTH]; + bool into_construct = FALSE; const char *label = NULL; STRLEN label_len = 0; U32 label_flags = 0; @@ -3652,9 +3653,7 @@ PP(pp_goto) ? 2 : 1; if (enterops[i]) - deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT, - "5.42", - "Use of \"goto\" to jump into a construct"); + into_construct = TRUE; } /* pop unwanted frames */ @@ -3686,6 +3685,12 @@ PP(pp_goto) } } + if (into_construct) + deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT, + "5.42", + "Use of \"goto\" to jump into a construct"); + + if (do_dump) { #ifdef VMS if (!retop) retop = PL_main_start; diff --git a/t/lib/croak/pp_ctl b/t/lib/croak/pp_ctl index 915fea9d54..b9f9f01ac1 100644 --- a/t/lib/croak/pp_ctl +++ b/t/lib/croak/pp_ctl @@ -1,23 +1,20 @@ __END__ # NAME goto into foreach -no warnings 'deprecated'; goto f; foreach(1){f:} EXPECT -Can't "goto" into the middle of a foreach loop at - line 3. +Can't "goto" into the middle of a foreach loop at - line 2. ######## # NAME goto into given -no warnings 'deprecated'; goto f; CORE::given(1){f:} EXPECT -Can't "goto" into a "given" block at - line 3. +Can't "goto" into a "given" block at - line 2. ######## # NAME goto from given topic expression -no warnings 'deprecated'; CORE::given(goto f){f:} EXPECT -Can't "goto" into a "given" block at - line 2. +Can't "goto" into a "given" block at - line 1. ######## # NAME goto into expression eval { goto a; 1 + do { a: } }; warn $@;