"redundant argument in printf" warning and computed field widths #14772
Comments
From karl@freefriends.orgThis is a bug report for perl from karl@freefriends.org, The perlfunc doc (aka http://perldoc.perl.org/functions/sprintf.html) printf '<%*2$s>', "a", 6; # prints "< a>" Running it with perl -w, in perl 5.22.0, produces a warning: Redundant argument in printf at try.pl line 1. Maybe I'm missing something obvious, but it sure seems like both Thanks, Flags: Site configuration information for perl 5.22.0: Configured by karl at Sat Jun 13 07:10:09 MDT 2015. Summary of my perl5 (revision 5 version 22 subversion 0) configuration: @INC for perl 5.22.0: Environment for perl 5.22.0: |
From @jkeenanOn Tue Jun 23 16:01:23 2015, karl@freefriends.org wrote:
I agree. Relevant documentation from pod/perldiag.pod and pod/perlfunc.pod (blead): ##### (W redundant) You called a function with more arguments than other =over 4 =item format parameter index An explicit format parameter index, such as C<2$>. By default sprintf printf '%2$d %1$d', 12, 34; # prints "34 12" Arguments are usually formatted to be only as wide as required to printf "<%s>", "a"; # prints "<a>"
-- |
The RT System itself - Status changed from 'new' to 'open' |
From @arcvia RT <perlbug-followup@perl.org> wrote:
Thanks for the report. I agree that it's incorrect for Perl to emit This patch against blead is currently smoking as smoke-me/arc/rt125469: From: Aaron Crane <arc@cpan.org> - RT#125469 points out that no "redundant argument" warning should be emitted - We no longer emit a "missing argument" warning for invalid format strings, - We no longer treat the invalid format string in C<< printf '%1$$d', 17 >> sv.c | 65 ++++++++++++++++++++++++++++++++++++---------------------- Inline Patchdiff --git a/sv.c b/sv.c
index b4a36e5..d3debba 100644
--- a/sv.c
+++ b/sv.c
@@ -10594,16 +10594,16 @@ Perl_sv_vsetpvfn(pTHX_ SV *const sv, const
/* @@ -11032,6 +11032,17 @@ S_hextract(pTHX_ const NV nv, int* exponent, +/* Helper for sv_vcatpvfn_flags(). */ @@ -11680,7 +11691,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, /* UNKNOWN */ @@ -12572,6 +12583,12 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, /* Now that we've consumed all our printf format arguments (svix) Inline Patchdiff --git a/t/op/sprintf.t b/t/op/sprintf.t
index c927a94..e11287c 100644
--- a/t/op/sprintf.t
+++ b/t/op/sprintf.t
@@ -647,7 +647,8 @@ __END__
>%y< >''< >%y INVALID REDUNDANT<
>%z< >''< >%z INVALID REDUNDANT<
>%2$d %1$d< >[12, 34]< >34 12<
->%*2$d< >[12, 3]< > 12 REDUNDANT<
+>%*2$d< >[12, 3]< > 12< >RT#125469<
+>%*3$d< >[12, 9, 3]< > 12< >related to RT#125469<
>%2$d %d< >[12, 34]< >34 12<
>%2$d %d %d< >[12, 34]< >34 12 34<
>%3$d %d %d< >[12, 34, 56]< >56 12 34<
@@ -655,8 +656,8 @@ __END__
>%*3$2$d %d< >[12, 34, 3]< >%*3$2$d 12 INVALID REDUNDANT<
>%2$d< >12< >0 MISSING<
>%0$d< >12< >%0$d INVALID REDUNDANT<
->%1$$d< >12< >%1$$d INVALID<
->%1$1$d< >12< >%1$1$d INVALID<
+>%1$$d< >12< >%1$$d INVALID REDUNDANT<
+>%1$1$d< >12< >%1$1$d INVALID REDUNDANT<
>%*2$*2$d< >[12, 3]< >%*2$*2$d INVALID REDUNDANT<
>%*2*2$d< >[12, 3]< >%*2*2$d INVALID REDUNDANT<
>%*2$1d< >[12, 3]< >%*2$1d INVALID REDUNDANT<
@@ -713,7 +714,7 @@ __END__
>%V-%s< >["Hello"]< >%V-Hello INVALID<
>%K %d %d< >[13, 29]< >%K 13 29 INVALID<
>%*.*K %d< >[13, 29, 76]< >%*.*K 13 INVALID REDUNDANT<
->%4$K %d< >[45, 67]< >%4$K 45 MISSING INVALID<
+>%4$K %d< >[45, 67]< >%4$K 45 INVALID REDUNDANT<
>%d %K %d< >[23, 45]< >23 %K 45 INVALID<
>%*v*999\$d %d %d< >[11, 22, 33]< >%*v*999\$d 11 22 INVALID REDUNDANT<
>%#b< >0< >0<
From: Aaron Crane <arc@cpan.org> This addresses RT#125469: if the format string uses an explicit index for a Blead has a more careful reworking of the way printf warnings work, but that sv.c | 7 +++++-- Inline Patchdiff --git a/sv.c b/sv.c
index 8440763..6afc5a6 100644
--- a/sv.c
+++ b/sv.c
@@ -11522,9 +11522,12 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv,
Inline Patchdiff --git a/t/op/sprintf.t b/t/op/sprintf.t
index 967b5d3..e6ef617 100644
--- a/t/op/sprintf.t
+++ b/t/op/sprintf.t
@@ -647,19 +647,20 @@ __END__
>%y< >''< >%y INVALID REDUNDANT<
>%z< >''< >%z INVALID REDUNDANT<
>%2$d %1$d< >[12, 34]< >34 12<
->%*2$d< >[12, 3]< > 12 REDUNDANT<
+>%*2$d< >[12, 3]< > 12< >RT#125469<
+>%*3$d< >[12, 9, 3]< > 12< >related to RT#125469<
>%2$d %d< >[12, 34]< >34 12<
>%2$d %d %d< >[12, 34]< >34 12 34<
>%3$d %d %d< >[12, 34, 56]< >56 12 34<
>%2$*3$d %d< >[12, 34, 3]< > 34 12<
->%*3$2$d %d< >[12, 34, 3]< >%*3$2$d 12 INVALID REDUNDANT<
+>%*3$2$d %d< >[12, 34, 3]< >%*3$2$d 12 INVALID<
>%2$d< >12< >0 MISSING<
>%0$d< >12< >%0$d INVALID REDUNDANT<
>%1$$d< >12< >%1$$d INVALID<
>%1$1$d< >12< >%1$1$d INVALID<
->%*2$*2$d< >[12, 3]< >%*2$*2$d INVALID REDUNDANT<
+>%*2$*2$d< >[12, 3]< >%*2$*2$d INVALID<
>%*2*2$d< >[12, 3]< >%*2*2$d INVALID REDUNDANT<
->%*2$1d< >[12, 3]< >%*2$1d INVALID REDUNDANT<
+>%*2$1d< >[12, 3]< >%*2$1d INVALID<
>%0v2.2d< >''< ><
>%vc,%d< >[63, 64, 65]< >%vc,63 INVALID REDUNDANT<
>%v%,%d< >[63, 64, 65]< >%v%,63 INVALID REDUNDANT<
-- Aaron Crane ** http://aaroncrane.co.uk/ |
From @steve-m-hayOn Mon Jun 29 09:02:52 2015, arc wrote:
This has now been applied to maint-5.22, ready for release in 5.22.1, by the following commit: http://perl5.git.perl.org/perl.git/commit/802475c8d28a32d1dfca9e93e7c06560c1483093 |
From @steve-m-hayOn Thu Oct 08 09:57:56 2015, shay wrote:
And it looks like the blead change was applied to blead a while back by this commit: http://perl5.git.perl.org/perl.git/commit/082ce9c667e6d73783164fa1abab61806b678b4f I'm therefore changing the status to 'pending release'. |
@steve-m-hay - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for submitting this report. You have helped make Perl better. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0 |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#125469 (status was 'resolved')
Searchable as RT125469$
The text was updated successfully, but these errors were encountered: