summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHauke D <haukex@zero-g.net>2014-01-13 00:50:51 +0100
committerTony Cook <tony@develop-help.com>2014-01-22 16:32:14 +1100
commitc91312d5e67fd262ccd6f36ff40ddbca6896d004 (patch)
tree95057cfca0a55d90b2a3af13205b44701698c773
parente214621be67f417c619e2038fcb4742892fde1b1 (diff)
downloadperl-c91312d5e67fd262ccd6f36ff40ddbca6896d004.tar.gz
assume "all" in "use warnings 'FATAL';" and related
Until now, the behavior of the statements use warnings "FATAL"; use warnings "NONFATAL"; no warnings "FATAL"; was unspecified and inconsistent. This change causes them to be handled with an implied "all" at the end of the import list. Tony Cook: fix AUTHORS formatting
-rw-r--r--AUTHORS1
-rw-r--r--lib/warnings.pm6
-rw-r--r--pod/perllexwarn.pod13
-rw-r--r--regen/warnings.pl6
-rw-r--r--t/lib/warnings/7fatal99
5 files changed, 123 insertions, 2 deletions
diff --git a/AUTHORS b/AUTHORS
index e66c2760be..824b8bdd18 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -460,6 +460,7 @@ Harmen <harm@dds.nl>
Harmon S. Nine <hnine@netarx.com>
Harri Pasanen <harri.pasanen@trema.com>
Harry Edmon <harry@atmos.washington.edu>
+Hauke D <haukex@zero-g.net>
Helmut Jarausch <jarausch@numa1.igpm.rwth-aachen.de>
Henrik Tougaard <ht.000@foa.dk>
Herbert Breunung <lichtkind@cpan.org>
diff --git a/lib/warnings.pm b/lib/warnings.pm
index c42a81996e..738a832bb6 100644
--- a/lib/warnings.pm
+++ b/lib/warnings.pm
@@ -424,6 +424,9 @@ sub import
$mask |= $Bits{'all'} ;
$mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
}
+
+ # append 'all' when implied (after a lone "FATAL" or "NONFATAL")
+ push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' );
# Empty @_ is equivalent to @_ = 'all' ;
${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
@@ -441,7 +444,8 @@ sub unimport
$mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
}
- push @_, 'all' unless @_;
+ # append 'all' when implied (empty import list or after a lone "FATAL")
+ push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
foreach my $word ( @_ ) {
if ($word eq 'FATAL') {
diff --git a/pod/perllexwarn.pod b/pod/perllexwarn.pod
index 4a41789237..b4fed79ca1 100644
--- a/pod/perllexwarn.pod
+++ b/pod/perllexwarn.pod
@@ -405,6 +405,19 @@ except for those in the "syntax" category.
use warnings FATAL => 'all', NONFATAL => 'syntax';
+As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
+use:
+
+ use v5.20; # Perl 5.20 or greater is required for the following
+ use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
+
+If you want your program to be compatible with versions of Perl before
+5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
+previous versions of Perl, the behavior of the statements
+C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
+C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
+they included the C<< => 'all' >> portion. As of 5.20, they do.)
+
B<NOTE:> Users of FATAL warnings, especially
those using C<< FATAL => 'all' >>
should be fully aware that they are risking future portability of their
diff --git a/regen/warnings.pl b/regen/warnings.pl
index 27e4d5003d..388b8a7858 100644
--- a/regen/warnings.pl
+++ b/regen/warnings.pl
@@ -693,6 +693,9 @@ sub import
$mask |= $Bits{'all'} ;
$mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
}
+
+ # append 'all' when implied (after a lone "FATAL" or "NONFATAL")
+ push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' );
# Empty @_ is equivalent to @_ = 'all' ;
${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
@@ -710,7 +713,8 @@ sub unimport
$mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
}
- push @_, 'all' unless @_;
+ # append 'all' when implied (empty import list or after a lone "FATAL")
+ push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
foreach my $word ( @_ ) {
if ($word eq 'FATAL') {
diff --git a/t/lib/warnings/7fatal b/t/lib/warnings/7fatal
index 6eeac741c2..32d2f19a36 100644
--- a/t/lib/warnings/7fatal
+++ b/t/lib/warnings/7fatal
@@ -433,3 +433,102 @@ print STDERR "The End.\n" ;
EXPECT
Unsuccessful open on filename containing newline at - line 5.
close() on unopened filehandle fred at - line 6.
+########
+
+# 'use warnings' test as the basis for the following tests
+use warnings ;
+my $a = oct "7777777777777777777777777777777777778" ;
+my $b =+ 1 ;
+my $c ; chop $c ;
+print STDERR "The End.\n" ;
+EXPECT
+Reversed += operator at - line 5.
+Integer overflow in octal number at - line 4.
+Illegal octal digit '8' ignored at - line 4.
+Octal number > 037777777777 non-portable at - line 4.
+Use of uninitialized value $c in scalar chop at - line 6.
+The End.
+########
+
+# 'use warnings NONFATAL=>"all"' should be the same as 'use warnings'
+use warnings NONFATAL=>"all" ;
+my $a = oct "7777777777777777777777777777777777778" ;
+my $b =+ 1 ;
+my $c ; chop $c ;
+print STDERR "The End.\n" ;
+EXPECT
+Reversed += operator at - line 5.
+Integer overflow in octal number at - line 4.
+Illegal octal digit '8' ignored at - line 4.
+Octal number > 037777777777 non-portable at - line 4.
+Use of uninitialized value $c in scalar chop at - line 6.
+The End.
+########
+
+# 'use warnings "NONFATAL"' should be the same as 'use warnings' [perl #120977]
+use warnings "NONFATAL" ;
+my $a = oct "7777777777777777777777777777777777778" ;
+my $b =+ 1 ;
+my $c ; chop $c ;
+print STDERR "The End.\n" ;
+EXPECT
+Reversed += operator at - line 5.
+Integer overflow in octal number at - line 4.
+Illegal octal digit '8' ignored at - line 4.
+Octal number > 037777777777 non-portable at - line 4.
+Use of uninitialized value $c in scalar chop at - line 6.
+The End.
+########
+
+# 'use warnings "FATAL"' should be the same as 'use warnings FATAL=>"all"' [perl #120977]
+use warnings "FATAL" ;
+{
+ no warnings ;
+ my $a =+ 1 ;
+}
+my $a =+ 1 ;
+print STDERR "The End.\n" ;
+EXPECT
+Reversed += operator at - line 8.
+########
+
+# 'use warnings "FATAL"' should be the same as 'use warnings FATAL=>"all"' [perl #120977]
+use warnings "FATAL" ;
+{
+ no warnings ;
+ my $a = oct "7777777777777777777777777777777777778" ;
+}
+my $a = oct "7777777777777777777777777777777777778" ;
+print STDERR "The End.\n" ;
+EXPECT
+Integer overflow in octal number at - line 8.
+########
+
+# 'no warnings FATAL=>"all"' should be the same as 'no warnings'
+use warnings ;
+{
+ no warnings FATAL=>"all" ;
+ my $a = oct "7777777777777777777777777777777777778" ;
+ my $b =+ 1 ;
+ my $c ; chop $c ;
+}
+my $a =+ 1 ;
+print STDERR "The End.\n" ;
+EXPECT
+Reversed += operator at - line 10.
+The End.
+########
+
+# 'no warnings "FATAL"' should be the same as 'no warnings' [perl #120977]
+use warnings ;
+{
+ no warnings "FATAL" ;
+ my $a = oct "7777777777777777777777777777777777778" ;
+ my $b =+ 1 ;
+ my $c ; chop $c ;
+}
+my $a =+ 1 ;
+print STDERR "The End.\n" ;
+EXPECT
+Reversed += operator at - line 10.
+The End.