assume "all" in "use warnings 'FATAL';" and related
authorHauke D <haukex@zero-g.net>
Sun, 12 Jan 2014 23:50:51 +0000 (00:50 +0100)
committerTony Cook <tony@develop-help.com>
Wed, 22 Jan 2014 05:32:14 +0000 (16:32 +1100)
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

AUTHORS
lib/warnings.pm
pod/perllexwarn.pod
regen/warnings.pl
t/lib/warnings/7fatal

diff --git a/AUTHORS b/AUTHORS
index e66c276..824b8bd 100644 (file)
--- 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>
index c42a819..738a832 100644 (file)
@@ -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') {
index 4a41789..b4fed79 100644 (file)
@@ -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
index 27e4d50..388b8a7 100644 (file)
@@ -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') {
index 6eeac74..32d2f19 100644 (file)
@@ -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.