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
Fixes #16275
  • Loading branch information
jkeenan committed Oct 28, 2023
1 parent e97277e commit b26cac2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 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
4 changes: 2 additions & 2 deletions pod/perlfunc.pod
Expand Up @@ -3633,8 +3633,8 @@ block. In general, it may not be used to jump into the parameter
of a binary or list operator, but it may be used to jump into the
I<first> parameter of a binary operator. (The C<=>
assignment operator's "first" operand is its right-hand
operand.) It also can't be used to go into a
construct that is optimized away.
operand.) It also can't be used to go into a construct that is optimized
away. Finally, it will be made into a fatal exception in Perl 5.42.

The C<goto &NAME> form is quite different from the other forms of
L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at
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 b26cac2

Please sign in to comment.