Skip to content

Commit c91312d

Browse files
haukextonycoz
authored andcommitted
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
1 parent e214621 commit c91312d

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ Harmen <[email protected]>
460460
Harmon S. Nine <[email protected]>
461461
Harri Pasanen <[email protected]>
462462
Harry Edmon <[email protected]>
463+
463464
Helmut Jarausch <[email protected]>
464465
Henrik Tougaard <[email protected]>
465466
Herbert Breunung <[email protected]>

lib/warnings.pm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ sub import
424424
$mask |= $Bits{'all'} ;
425425
$mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
426426
}
427+
428+
# append 'all' when implied (after a lone "FATAL" or "NONFATAL")
429+
push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' );
427430

428431
# Empty @_ is equivalent to @_ = 'all' ;
429432
${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
@@ -441,7 +444,8 @@ sub unimport
441444
$mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
442445
}
443446

444-
push @_, 'all' unless @_;
447+
# append 'all' when implied (empty import list or after a lone "FATAL")
448+
push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
445449

446450
foreach my $word ( @_ ) {
447451
if ($word eq 'FATAL') {

pod/perllexwarn.pod

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,19 @@ except for those in the "syntax" category.
405405

406406
use warnings FATAL => 'all', NONFATAL => 'syntax';
407407

408+
As of Perl 5.20, instead of C<< use warnings FATAL => 'all'; >> you can
409+
use:
410+
411+
use v5.20; # Perl 5.20 or greater is required for the following
412+
use warnings 'FATAL'; # short form of "use warnings FATAL => 'all';"
413+
414+
If you want your program to be compatible with versions of Perl before
415+
5.20, you must use C<< use warnings FATAL => 'all'; >> instead. (In
416+
previous versions of Perl, the behavior of the statements
417+
C<< use warnings 'FATAL'; >>, C<< use warnings 'NONFATAL'; >> and
418+
C<< no warnings 'FATAL'; >> was unspecified; they did not behave as if
419+
they included the C<< => 'all' >> portion. As of 5.20, they do.)
420+
408421
B<NOTE:> Users of FATAL warnings, especially
409422
those using C<< FATAL => 'all' >>
410423
should be fully aware that they are risking future portability of their

regen/warnings.pl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,9 @@ sub import
693693
$mask |= $Bits{'all'} ;
694694
$mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
695695
}
696+
697+
# append 'all' when implied (after a lone "FATAL" or "NONFATAL")
698+
push @_, 'all' if @_==1 && ( $_[0] eq 'FATAL' || $_[0] eq 'NONFATAL' );
696699
697700
# Empty @_ is equivalent to @_ = 'all' ;
698701
${^WARNING_BITS} = @_ ? _bits($mask, @_) : $mask | $Bits{all} ;
@@ -710,7 +713,8 @@ sub unimport
710713
$mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
711714
}
712715
713-
push @_, 'all' unless @_;
716+
# append 'all' when implied (empty import list or after a lone "FATAL")
717+
push @_, 'all' if !@_ || @_==1 && $_[0] eq 'FATAL';
714718
715719
foreach my $word ( @_ ) {
716720
if ($word eq 'FATAL') {

t/lib/warnings/7fatal

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,102 @@ print STDERR "The End.\n" ;
433433
EXPECT
434434
Unsuccessful open on filename containing newline at - line 5.
435435
close() on unopened filehandle fred at - line 6.
436+
########
437+
438+
# 'use warnings' test as the basis for the following tests
439+
use warnings ;
440+
my $a = oct "7777777777777777777777777777777777778" ;
441+
my $b =+ 1 ;
442+
my $c ; chop $c ;
443+
print STDERR "The End.\n" ;
444+
EXPECT
445+
Reversed += operator at - line 5.
446+
Integer overflow in octal number at - line 4.
447+
Illegal octal digit '8' ignored at - line 4.
448+
Octal number > 037777777777 non-portable at - line 4.
449+
Use of uninitialized value $c in scalar chop at - line 6.
450+
The End.
451+
########
452+
453+
# 'use warnings NONFATAL=>"all"' should be the same as 'use warnings'
454+
use warnings NONFATAL=>"all" ;
455+
my $a = oct "7777777777777777777777777777777777778" ;
456+
my $b =+ 1 ;
457+
my $c ; chop $c ;
458+
print STDERR "The End.\n" ;
459+
EXPECT
460+
Reversed += operator at - line 5.
461+
Integer overflow in octal number at - line 4.
462+
Illegal octal digit '8' ignored at - line 4.
463+
Octal number > 037777777777 non-portable at - line 4.
464+
Use of uninitialized value $c in scalar chop at - line 6.
465+
The End.
466+
########
467+
468+
# 'use warnings "NONFATAL"' should be the same as 'use warnings' [perl #120977]
469+
use warnings "NONFATAL" ;
470+
my $a = oct "7777777777777777777777777777777777778" ;
471+
my $b =+ 1 ;
472+
my $c ; chop $c ;
473+
print STDERR "The End.\n" ;
474+
EXPECT
475+
Reversed += operator at - line 5.
476+
Integer overflow in octal number at - line 4.
477+
Illegal octal digit '8' ignored at - line 4.
478+
Octal number > 037777777777 non-portable at - line 4.
479+
Use of uninitialized value $c in scalar chop at - line 6.
480+
The End.
481+
########
482+
483+
# 'use warnings "FATAL"' should be the same as 'use warnings FATAL=>"all"' [perl #120977]
484+
use warnings "FATAL" ;
485+
{
486+
no warnings ;
487+
my $a =+ 1 ;
488+
}
489+
my $a =+ 1 ;
490+
print STDERR "The End.\n" ;
491+
EXPECT
492+
Reversed += operator at - line 8.
493+
########
494+
495+
# 'use warnings "FATAL"' should be the same as 'use warnings FATAL=>"all"' [perl #120977]
496+
use warnings "FATAL" ;
497+
{
498+
no warnings ;
499+
my $a = oct "7777777777777777777777777777777777778" ;
500+
}
501+
my $a = oct "7777777777777777777777777777777777778" ;
502+
print STDERR "The End.\n" ;
503+
EXPECT
504+
Integer overflow in octal number at - line 8.
505+
########
506+
507+
# 'no warnings FATAL=>"all"' should be the same as 'no warnings'
508+
use warnings ;
509+
{
510+
no warnings FATAL=>"all" ;
511+
my $a = oct "7777777777777777777777777777777777778" ;
512+
my $b =+ 1 ;
513+
my $c ; chop $c ;
514+
}
515+
my $a =+ 1 ;
516+
print STDERR "The End.\n" ;
517+
EXPECT
518+
Reversed += operator at - line 10.
519+
The End.
520+
########
521+
522+
# 'no warnings "FATAL"' should be the same as 'no warnings' [perl #120977]
523+
use warnings ;
524+
{
525+
no warnings "FATAL" ;
526+
my $a = oct "7777777777777777777777777777777777778" ;
527+
my $b =+ 1 ;
528+
my $c ; chop $c ;
529+
}
530+
my $a =+ 1 ;
531+
print STDERR "The End.\n" ;
532+
EXPECT
533+
Reversed += operator at - line 10.
534+
The End.

0 commit comments

Comments
 (0)