Skip to content

Commit aa8cd16

Browse files
committed
Fatalize use of goto to jump into construct
Fixes: GH #23618
1 parent 656be9b commit aa8cd16

File tree

7 files changed

+138
-367
lines changed

7 files changed

+138
-367
lines changed

pod/perldiag.pod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7845,6 +7845,10 @@ For speed and efficiency reasons, Perl internally does not do full
78457845
reference-counting of iterated items, hence deleting such an item in the
78467846
middle of an iteration causes Perl to see a freed value.
78477847

7848+
=item Use of "goto" to jump into a construct is no longer permitted
7849+
7850+
(F) More TO COME.
7851+
78487852
=item Use of /g modifier is meaningless in split
78497853

78507854
(W regexp) You used the /g modifier on the pattern for a C<split>

pp_ctl.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3652,9 +3652,7 @@ PP(pp_goto)
36523652
? 2
36533653
: 1;
36543654
if (enterops[i])
3655-
deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT,
3656-
"5.42",
3657-
"Use of \"goto\" to jump into a construct");
3655+
croak("Use of \"goto\" to jump into a construct is no longer permitted");
36583656
}
36593657

36603658
/* pop unwanted frames */

t/comp/package_block.t

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!./perl
22

3-
print "1..7\n";
3+
print "1..5\n";
44

55
$main::result = "";
66
eval q{
@@ -56,37 +56,4 @@ eval q{
5656
};
5757
print $main::result eq "a(2)b(4)c(6)d(8)e(10)f(12)" ? "ok 5\n" : "not ok 5\n";
5858

59-
$main::result = "";
60-
$main::warning = "";
61-
$SIG{__WARN__} = sub { $main::warning .= $_[0]; };
62-
eval q{
63-
$main::result .= "a(".__PACKAGE__."/".eval("__PACKAGE__").")";
64-
goto l0;
65-
$main::result .= "b(".__PACKAGE__."/".eval("__PACKAGE__").")";
66-
package Foo {
67-
$main::result .= "c(".__PACKAGE__."/".eval("__PACKAGE__").")";
68-
l0:
69-
$main::result .= "d(".__PACKAGE__."/".eval("__PACKAGE__").")";
70-
goto l1;
71-
$main::result .= "e(".__PACKAGE__."/".eval("__PACKAGE__").")";
72-
}
73-
$main::result .= "f(".__PACKAGE__."/".eval("__PACKAGE__").")";
74-
l1:
75-
$main::result .= "g(".__PACKAGE__."/".eval("__PACKAGE__").")";
76-
goto l2;
77-
$main::result .= "h(".__PACKAGE__."/".eval("__PACKAGE__").")";
78-
package Bar {
79-
l2:
80-
$main::result .= "i(".__PACKAGE__."/".eval("__PACKAGE__").")";
81-
}
82-
$main::result .= "j(".__PACKAGE__."/".eval("__PACKAGE__").")";
83-
};
84-
print $main::result eq
85-
"a(main/main)d(Foo/Foo)g(main/main)i(Bar/Bar)j(main/main)" ?
86-
"ok 6\n" : "not ok 6\n";
87-
print $main::warning =~ /\A
88-
Use\ of\ "goto"\ [^\n]*\ line\ 3\.\n
89-
Use\ of\ "goto"\ [^\n]*\ line\ 15\.\n
90-
\z/x ? "ok 7\n" : "not ok 7\n";
91-
9259
1;

t/lib/croak/pp_ctl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
__END__
22
# NAME goto into foreach
3-
no warnings 'deprecated';
43
goto f;
54
foreach(1){f:}
65
EXPECT
7-
Can't "goto" into the middle of a foreach loop at - line 3.
6+
Use of "goto" to jump into a construct is no longer permitted at - line 1.
87
########
98
# NAME goto into given
10-
no warnings 'deprecated';
119
goto f;
1210
CORE::given(1){f:}
1311
EXPECT
14-
Can't "goto" into a "given" block at - line 3.
12+
Use of "goto" to jump into a construct is no longer permitted at - line 1.
1513
########
1614
# NAME goto from given topic expression
17-
no warnings 'deprecated';
1815
CORE::given(goto f){f:}
1916
EXPECT
20-
Can't "goto" into a "given" block at - line 2.
17+
Use of "goto" to jump into a construct is no longer permitted at - line 1.
2118
########
2219
# NAME goto into expression
2320
no warnings 'deprecated';

0 commit comments

Comments
 (0)