The Perl interpreter is careful to use the line number of the start of a
subroutine's redefinition for the warning, but there were no tests for this.
#endif
) {
const line_t oldline = CopLINE(PL_curcop);
- if (PL_parser && PL_parser->copline != NOLINE)
+ if (PL_parser && PL_parser->copline != NOLINE) {
+ /* This ensures that warnings are reported at the first
+ line of a redefinition, not the last. */
CopLINE_set(PL_curcop, PL_parser->copline);
+ }
report_redefined_cv(cSVOPo->op_sv, cv, &const_sv);
CopLINE_set(PL_curcop, oldline);
#ifdef PERL_MAD
use warnings 'redefine' ;
sub fred {}
sub fred {}
+sub fred { # warning should be for this line
+}
no warnings 'redefine' ;
sub fred {}
+sub fred {
+}
EXPECT
Subroutine fred redefined at - line 4.
+Subroutine fred redefined at - line 5.
########
# op.c
use warnings 'redefine' ;