Skip to content

Commit

Permalink
Announce 5.42 removal of goto to jump into construct
Browse files Browse the repository at this point in the history
perlfunc: clarify documentation per suggestion from Hugo van der Sanden in
#21601.

Fixes #16275
  • Loading branch information
jkeenan committed Nov 5, 2023
1 parent fbca050 commit a23e475
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pod/perldiag.pod
Expand Up @@ -7664,7 +7664,7 @@ repeatedly, the C</g> has no effect.
=item Use of "goto" to jump into a construct is deprecated

(D deprecated::goto_construct) Using C<goto> to jump from an outer scope into an inner
scope is deprecated and should be avoided.
scope is deprecated and will be removed completely in Perl 5.42.

This was deprecated in Perl 5.12.

Expand Down
3 changes: 2 additions & 1 deletion pod/perlfunc.pod
Expand Up @@ -3626,7 +3626,8 @@ Also, unlike most named operators, this has the same precedence as
assignment.

Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is
deprecated and will issue a warning. Even then, it may not be used to
deprecated and will issue a warning; it will become a fatal error in
Perl 5.42. While still available, it may not be used to
go into any construct that requires initialization, such as a
subroutine, a C<foreach> loop, or a C<given>
block. In general, it may not be used to jump into the parameter
Expand Down
4 changes: 3 additions & 1 deletion pp_ctl.c
Expand Up @@ -3552,7 +3552,9 @@ PP(pp_goto)
? 2
: 1;
if (enterops[i])
deprecate(WARN_DEPRECATED__GOTO_CONSTRUCT, "Use of \"goto\" to jump into a construct");
deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT,
"5.42",
"Use of \"goto\" to jump into a construct");
}

/* pop unwanted frames */
Expand Down
8 changes: 7 additions & 1 deletion t/op/goto.t
Expand Up @@ -16,7 +16,13 @@ plan tests => 134;
our $TODO;

my $deprecated = 0;
local $SIG{__WARN__} = sub { if ($_[0] =~ m/jump into a construct/) { $deprecated++; } else { warn $_[0] } };

local $SIG{__WARN__} = sub {
if ($_[0] =~ m/jump into a construct.*?, and will become fatal in Perl 5\.42/) {
$deprecated++;
}
else { warn $_[0] }
};

our $foo;
while ($?) {
Expand Down
2 changes: 1 addition & 1 deletion t/porting/deprecation.t
Expand Up @@ -103,7 +103,7 @@ if (-e ".git") {
goto LABEL;
DONE:
like($warning,
qr/Use of "goto" to jump into a construct is deprecated/,
qr/Use of "goto" to jump into a construct is deprecated, and will become fatal in Perl 5\.42/,
"Got expected deprecation warning");
}
# Test that we can silence deprecation warnings with "no warnings 'deprecated'"
Expand Down

0 comments on commit a23e475

Please sign in to comment.