Finally, this "Negative repeat count" warning wasn't such a great
authorAndy Lester <andy@petdance.com>
Sun, 21 Mar 2004 09:27:04 +0000 (03:27 -0600)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sun, 21 Mar 2004 17:22:42 +0000 (17:22 +0000)
idea. Disable it. But add tests for this :

Subject: Re: [perl #27811] (@x) x -1 is a panic
Message-ID: <20040321152704.GA9041@petdance.com>

p4raw-id: //depot/perl@22549

pp.c
t/lib/warnings/pp
t/op/repeat.t

diff --git a/pp.c b/pp.c
index 53c7162..4c3e377 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -1386,11 +1386,8 @@ PP(pp_repeat)
   dSP; dATARGET; tryAMAGICbin(repeat,opASSIGN);
   {
     register IV count = POPi;
-    if (count < 0) {
-       if (ckWARN(WARN_MISC))
-           Perl_warner(aTHX_ packWARN(WARN_MISC), "Negative repeat count");
+    if (count < 0)
        count = 0;
-    }
     if (GIMME == G_ARRAY && PL_op->op_private & OPpREPEAT_DOLIST) {
        dMARK;
        I32 items = SP - MARK;
index db42027..5ed7aa0 100644 (file)
@@ -102,12 +102,3 @@ use utf8 ;
 $_ = "\x80  \xff" ;
 reverse ;
 EXPECT
-########
-# pp.c
-use warnings;
-$a = "b" x -1;
-$a = "b" x 0;
-no warnings;
-$a = "b" x -1;
-EXPECT
-Negative repeat count at - line 3.
index 82fcf75..d1b9c94 100755 (executable)
@@ -6,13 +6,15 @@ BEGIN {
 }
 
 require './test.pl';
-plan(tests => 25);
+plan(tests => 33);
 
 # compile time
 
 is('-' x 5, '-----',    'compile time x');
 is('-' x 1, '-',        '  x 1');
 is('-' x 0, '',         '  x 0');
+is('-' x -1, '',        '  x -1');
+is('-' x undef, '',     '  x undef');
 
 is('ab' x 3, 'ababab',  '  more than one char');
 
@@ -22,9 +24,15 @@ $a = '-';
 is($a x 5, '-----',     'run time x');
 is($a x 1, '-',         '  x 1');
 is($a x 0, '',          '  x 0');
+is($a x -3, '',         '  x -3');
+is($a x undef, '',      '  x undef');
 
 $a = 'ab';
 is($a x 3, 'ababab',    '  more than one char');
+$a = 'ab';
+is($a x 0, '',          '  more than one char');
+$a = 'ab';
+is($a x -12, '',        '  more than one char');
 
 $a = 'xyz';
 $a x= 2;
@@ -45,6 +53,9 @@ is(join(':', (9) x 4),      '9:9:9:9',              '(X) x Y');
 is(join(':', (9,9) x 4),    '9:9:9:9:9:9:9:9',      '(X,X) x Y');
 is(join('', (split(//,"123")) x 2), '123123',       'split and x');
 
+is(join('', @x x -12),      '',                     '@x x -12');
+is(join('', (@x) x -14),    '',                     '(@x) x -14');
+
 
 # This test is actually testing for Digital C compiler optimizer bug,
 # present in Dec C versions 5.* and 6.0 (used in Digital UNIX and VMS),