Skip to content

Commit

Permalink
Revert "Remove deprecation warnings related to $* and $#."
Browse files Browse the repository at this point in the history
This reverts commit e9b5346.

We've decided that instead of leaving $* and $# as usuable, magic-free
variables, we instead make it fatal to use them. Therefore, we restore
the warnings their use gives, and in a subsequent commit, we fix the
warning to indicate the version where their use becomes fatal.
  • Loading branch information
Abigail committed Jan 16, 2017
1 parent 753c381 commit a678626
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 44 deletions.
14 changes: 14 additions & 0 deletions gv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,13 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len,
SvREADONLY_on(av);
}
break;
case '*': /* $* */
case '#': /* $# */
if (sv_type == SVt_PV)
/* diag_listed_as: $* is no longer supported */
Perl_ck_warner_d(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
"$%c is no longer supported", *name);
break;
case '\010': /* $^H */
{
HV *const hv = GvHVn(gv);
Expand Down Expand Up @@ -2260,6 +2267,13 @@ S_maybe_multimagic_gv(pTHX_ GV *gv, const char *name, const svtype sv_type)
require_tie_mod_s(gv, '!', "Errno", 1);
else if (*name == '-' || *name == '+')
require_tie_mod_s(gv, *name, "Tie::Hash::NamedCapture", 0);
} else if (sv_type == SVt_PV) {
if (*name == '*' || *name == '#') {
/* diag_listed_as: $* is no longer supported */
Perl_ck_warner_d(aTHX_ packWARN2(WARN_DEPRECATED,
WARN_SYNTAX),
"$%c is no longer supported", *name);
}
}
if (sv_type==SVt_PV || sv_type==SVt_PVGV) {
switch (*name) {
Expand Down
33 changes: 0 additions & 33 deletions pod/perldeprecation.pod
Original file line number Diff line number Diff line change
Expand Up @@ -423,39 +423,6 @@ To tie the handle, use C<tie *$scalar> (with an explicit asterisk). The same
applies to C<tied *$scalar> and C<untie *$scalar>.


=head2 Perl 5.10

=head3 $* is no longer supported

C<$*> was once a magic variable. C<$*> enabled or disabled
multi-line matching within a string. Deprecated since Perl 5.000,
its special meaning was removed in Perl 5.10. Aftwards, an
deprecation message was issued when using this variable; this message
was discontinued in Perl 5.26.

Instead of using C<$*> you should use the C</m> (and maybe C</s>) regexp
modifiers. You can enable C</m> for a lexical scope (even a whole file)
with C<use re '/m'>. (In older versions: when C<$*> was set to a true value
then all regular expressions behaved as if they were written using C</m>.)

Although you can use C<$*> as a normal variable, you are discouraged
from doing so.

=head3 $# is no longer supported

C<$#> was once a magic variable. C<$#> could be used to format
printed numbers. Deprecated since Perl 5.000,
its special meaning was removed in Perl 5.10. Aftwards, an
deprecation message was issued when using this variable; this message
was discontinued in Perl 5.26.

Instead of using C<$#>, you should be using C<(s)printf> to format
your numbers.

Although you can use C<$*> as a normal variable, you are discouraged
from doing so.


=head1 SEE ALSO

L<warnings>, L<diagnostics>.
Expand Down
18 changes: 18 additions & 0 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -3141,6 +3141,24 @@ You specified a character that has the given plainer way of writing it,
and which is also portable to platforms running with different character
sets. This usage is deprecated, and will be a fatal error in Perl 5.28.

=item $* is no longer supported

(D deprecated, syntax) The special variable C<$*>, deprecated in older
perls, has been removed as of 5.10.0 and is no longer supported. In
previous versions of perl the use of C<$*> enabled or disabled multi-line
matching within a string.

Instead of using C<$*> you should use the C</m> (and maybe C</s>) regexp
modifiers. You can enable C</m> for a lexical scope (even a whole file)
with C<use re '/m'>. (In older versions: when C<$*> was set to a true value
then all regular expressions behaved as if they were written using C</m>.)

=item $# is no longer supported

(D deprecated, syntax) The special variable C<$#>, deprecated in older
perls, has been removed as of 5.10.0 and is no longer supported. You
should use the printf/sprintf functions instead.

=item '%s' is not a code reference

(W overload) The second (fourth, sixth, ...) argument of
Expand Down
20 changes: 9 additions & 11 deletions t/lib/warnings/2use
Original file line number Diff line number Diff line change
Expand Up @@ -361,21 +361,19 @@ Use of uninitialized value $c in scalar chop at - line 9.
########

# Check that deprecation warnings are not implicitly disabled by use
our $foo :unique;
use warnings "void";
our $bar :unique;
$*;
use warnings "void";
$#;
EXPECT
Attribute "unique" is deprecated, and will disappear in Perl 5.28 at - line 3.
Attribute "unique" is deprecated, and will disappear in Perl 5.28 at - line 5.
Useless use of a variable in void context at - line 6.
$* is no longer supported at - line 3.
$# is no longer supported at - line 5.
Useless use of a variable in void context at - line 5.
########

# Check that deprecation warnings are not implicitly disabled by no
our $foo :unique;
no warnings "void";
our $bar :unique;
$*;
no warnings "void";
$#;
EXPECT
Attribute "unique" is deprecated, and will disappear in Perl 5.28 at - line 3.
Attribute "unique" is deprecated, and will disappear in Perl 5.28 at - line 5.
$* is no longer supported at - line 3.
$# is no longer supported at - line 5.
60 changes: 60 additions & 0 deletions t/lib/warnings/gv
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,66 @@ EXPECT
Use of inherited AUTOLOAD for non-method main::fᕃƌ() is deprecated. This will be fatal in Perl 5.28 at - line 7.
########
# gv.c
$a = ${"#"};
$a = ${"*"};
no warnings 'deprecated' ;
$a = ${"#"};
$a = ${"*"};
EXPECT
$# is no longer supported at - line 2.
$* is no longer supported at - line 3.
########
# gv.c
$a = ${#};
$a = ${*};
no warnings 'deprecated' ;
$a = ${#};
$a = ${*};
EXPECT
$# is no longer supported at - line 2.
$* is no longer supported at - line 3.
########
# gv.c
$a = $#;
$a = $*;
$# = $a;
$* = $a;
$a = \$#;
$a = \$*;
no warnings 'deprecated' ;
$a = $#;
$a = $*;
$# = $a;
$* = $a;
$a = \$#;
$a = \$*;
EXPECT
$# is no longer supported at - line 2.
$* is no longer supported at - line 3.
$# is no longer supported at - line 4.
$* is no longer supported at - line 5.
$# is no longer supported at - line 6.
$* is no longer supported at - line 7.
########
# gv.c
@a = @#;
@a = @*;
$a = $#;
$a = $*;
EXPECT
$# is no longer supported at - line 4.
$* is no longer supported at - line 5.
########
# gv.c
$a = $#;
$a = $*;
@a = @#;
@a = @*;
EXPECT
$# is no longer supported at - line 2.
$* is no longer supported at - line 3.
########
# gv.c
$a = ${^ENCODING};
$a = ${^E_NCODING};
${^ENCODING} = 1;
Expand Down

0 comments on commit a678626

Please sign in to comment.