This ‘Can't use an undefined value as a subroutine reference’ message
used to occur for &{+undef}, until commit
15ff848f77796 in 1997.
Then it started happening only for magic variables.
Non-magical variables would treat it the same as "", possibly dying
with ‘Undefined subroutine main:: called’, and possibly calling the
subroutine with that name.
Magical variables (&{$tied_undef}) started behaving the same way
(treating undef as "") with commit
7c75014e, in 2010.
This commit restores that message.
else {
const char *sym;
STRLEN len;
- sym = SvPV_nomg_const(sv, len);
- if (!sym)
+ if (!SvOK(sv))
DIE(aTHX_ PL_no_usym, "a subroutine");
+ sym = SvPV_nomg_const(sv, len);
if (PL_op->op_private & HINT_STRICT_REFS)
DIE(aTHX_ "Can't use string (\"%" SVf32 "\"%s) as a subroutine ref while \"strict refs\" in use", sv, len>32 ? "..." : "");
cv = get_cvn_flags(sym, len, GV_ADD|SvUTF8(sv));
&$foosub;
EXPECT
Undefined subroutine &main::foo called at - line 2.
+########
+# NAME calling undef scalar
+ &{+undef};
+EXPECT
+Can't use an undefined value as a subroutine reference at - line 1.
+########
+# NAME calling undef magical scalar
+ sub TIESCALAR {bless[]}
+ sub FETCH {}
+ tie $tied, "";
+ &$tied;
+EXPECT
+Can't use an undefined value as a subroutine reference at - line 4.
Use of uninitialized value $g1 in splice at - line 10.
Use of uninitialized value in addition (+) at - line 10.
Use of uninitialized value $m1 in method lookup at - line 13.
-Use of uninitialized value in subroutine entry at - line 15.
-Use of uninitialized value in subroutine entry at - line 16.
Use of uninitialized value $m1 in warn at - line 18.
Use of uninitialized value $g1 in warn at - line 18.
foo at - line 18.