From: Jarkko Hietaniemi Date: Wed, 2 May 2001 13:26:01 +0000 (+0000) Subject: Add a test for not griping about references as array X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f1cc344493de26d4fb2dc9d28a7a18134e67bc6;p=p5sagit%2Fp5-mst-13.2.git Add a test for not griping about references as array indices if the reference has magic in it (overloaded methods). p4raw-id: //depot/perl@9957 --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index eab0556..cd32d72 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -3778,14 +3778,16 @@ old way has bad side effects. (D deprecated) This was an ill-advised attempt to emulate a poorly defined B feature. Use an explicit printf() or sprintf() instead. -=item Use of reference "%s" in array index +=item Use of reference "%s" as array index (W) You tried to use a reference as an array index; this probably -isn't what you mean, because references tend to be huge numbers which -take you out of memory, and so usually indicates programmer error. +isn't what you mean, because references in numerical context tend +to be huge numbers, and so usually indicates programmer error. If you really do mean it, explicitly numify your reference, like so: -C<$array[0+$ref]> +C<$array[0+$ref]>. This warning is not given for overloaded objects, +either, because you can overload the numification and stringification +operators and then you assumedly know what you are doing. =item Use of reserved word "%s" is deprecated diff --git a/t/pragma/warn/pp_hot b/t/pragma/warn/pp_hot index 26aef63..b21117c 100644 --- a/t/pragma/warn/pp_hot +++ b/t/pragma/warn/pp_hot @@ -245,3 +245,21 @@ print $x[\1]; EXPECT OPTION regex Use of reference ".*" as array index at - line 4. +######## +# pp_hot.c [pp_aelem] +package Foo;use overload q("") => sub {};package main;$a = bless {}, "Foo"; +$b = {}; +{ +use warnings 'misc'; +print $x[$a]; +print $x[$b]; +} +{ +no warnings 'misc'; +print $x[$a]; +print $x[$b]; +} + +EXPECT +OPTION regex +Use of reference ".*" as array index at - line 7.