From: Andy Lester Date: Sun, 21 Mar 2004 09:27:04 +0000 (-0600) Subject: Finally, this "Negative repeat count" warning wasn't such a great X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b8c0df9bfb9b3699a23e8633f5ede3b929d4620;p=p5sagit%2Fp5-mst-13.2.git Finally, this "Negative repeat count" warning wasn't such a great 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 --- diff --git a/pp.c b/pp.c index 53c7162..4c3e377 100644 --- 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; diff --git a/t/lib/warnings/pp b/t/lib/warnings/pp index db42027..5ed7aa0 100644 --- a/t/lib/warnings/pp +++ b/t/lib/warnings/pp @@ -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. diff --git a/t/op/repeat.t b/t/op/repeat.t index 82fcf75..d1b9c94 100755 --- a/t/op/repeat.t +++ b/t/op/repeat.t @@ -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),