Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pod/perldiag.pod
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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