From: Dave Mitchell Date: Fri, 23 Apr 2004 20:43:02 +0000 (+0000) Subject: Include variable names in "Use of uninitialized value" warnings X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=29489e7c741791873ea464cb7e13d2b5a19577a7;p=p5sagit%2Fp5-mst-13.2.git Include variable names in "Use of uninitialized value" warnings p4raw-id: //depot/perl@22741 --- diff --git a/MANIFEST b/MANIFEST index 706275c..1e5a1c0 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2733,6 +2733,7 @@ t/lib/warnings/6default Tests default warnings t/lib/warnings/7fatal Tests fatal warnings t/lib/warnings/8signal Tests warnings + __WARN__ and __DIE__ t/lib/warnings/9enabled Tests warnings +t/lib/warnings/9uninit Tests "Use of uninitialized" warnings t/lib/warnings/av Tests for av.c for warnings.t t/lib/warnings/doio Tests for doio.c for warnings.t t/lib/warnings/doop Tests for doop.c for warnings.t diff --git a/doio.c b/doio.c index 760e8f1..98e7204 100644 --- a/doio.c +++ b/doio.c @@ -1270,7 +1270,7 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) switch (SvTYPE(sv)) { case SVt_NULL: if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); return TRUE; case SVt_IV: if (SvIOK(sv)) { diff --git a/embed.fnc b/embed.fnc index 8e0b5ca..1ee63c3 100644 --- a/embed.fnc +++ b/embed.fnc @@ -845,7 +845,7 @@ p |U32 |parse_unicode_opts|char **popt p |U32 |seed p |UV |get_hash_seed p |void |report_evil_fh |GV *gv|IO *io|I32 op -pd |void |report_uninit +pd |void |report_uninit |SV* uninit_sv Afpd |void |warn |const char* pat|... Ap |void |vwarn |const char* pat|va_list* args Afp |void |warner |U32 err|const char* pat|... @@ -1403,6 +1403,9 @@ Apd |void |hv_clear_placeholders|HV* hb Apd |SV* |hv_scalar |HV* hv| p |SV* |magic_scalarpack|HV* hv|MAGIC* mg +#ifdef PERL_IN_SV_C +sMd |SV* |find_uninit_var|OP* obase|SV* uninit_sv|bool top +#endif #ifdef PERL_NEED_MY_HTOLE16 np |U16 |my_htole16 |U16 n diff --git a/embed.h b/embed.h index 3de8118..4eef0bf 100644 --- a/embed.h +++ b/embed.h @@ -2155,6 +2155,11 @@ #ifdef PERL_CORE #define magic_scalarpack Perl_magic_scalarpack #endif +#ifdef PERL_IN_SV_C +#ifdef PERL_CORE +#define find_uninit_var S_find_uninit_var +#endif +#endif #ifdef PERL_NEED_MY_HTOLE16 #ifdef PERL_CORE #define my_htole16 Perl_my_htole16 @@ -3745,7 +3750,7 @@ #define report_evil_fh(a,b,c) Perl_report_evil_fh(aTHX_ a,b,c) #endif #ifdef PERL_CORE -#define report_uninit() Perl_report_uninit(aTHX) +#define report_uninit(a) Perl_report_uninit(aTHX_ a) #endif #define vwarn(a,b) Perl_vwarn(aTHX_ a,b) #define vwarner(a,b,c) Perl_vwarner(aTHX_ a,b,c) @@ -4770,6 +4775,11 @@ #ifdef PERL_CORE #define magic_scalarpack(a,b) Perl_magic_scalarpack(aTHX_ a,b) #endif +#ifdef PERL_IN_SV_C +#ifdef PERL_CORE +#define find_uninit_var(a,b,c) S_find_uninit_var(aTHX_ a,b,c) +#endif +#endif #ifdef PERL_NEED_MY_HTOLE16 #ifdef PERL_CORE #define my_htole16 Perl_my_htole16 diff --git a/ext/DB_File/DB_File.pm b/ext/DB_File/DB_File.pm index a965e82..b9fb63a 100644 --- a/ext/DB_File/DB_File.pm +++ b/ext/DB_File/DB_File.pm @@ -165,7 +165,7 @@ our ($db_version, $use_XSLoader, $splice_end_array); use Carp; -$VERSION = "1.808_01" ; +$VERSION = "1.808_02" ; { local $SIG{__WARN__} = sub {$splice_end_array = "@_";}; diff --git a/ext/DB_File/t/db-recno.t b/ext/DB_File/t/db-recno.t index 4ab0aeb..8bd6379 100755 --- a/ext/DB_File/t/db-recno.t +++ b/ext/DB_File/t/db-recno.t @@ -1313,6 +1313,8 @@ sub test_splice { foreach ($s_error, @s_warnings) { chomp; s/ at \S+ line \d+\.$//; + # only built-in splice identifies name of uninit value + s/(uninitialized value) \$\w+/$1/; } # Now do the same for DB_File's version of splice diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm index 7393b12..220920e 100644 --- a/lib/Math/BigInt.pm +++ b/lib/Math/BigInt.pm @@ -18,7 +18,7 @@ package Math::BigInt; my $class = "Math::BigInt"; require 5.005; -$VERSION = '1.70'; +$VERSION = '1.70_01'; use Exporter; @ISA = qw( Exporter ); @EXPORT_OK = qw( objectify bgcd blcm); diff --git a/lib/Math/BigInt/t/mbimbf.inc b/lib/Math/BigInt/t/mbimbf.inc index b9c94c4..51fea64 100644 --- a/lib/Math/BigInt/t/mbimbf.inc +++ b/lib/Math/BigInt/t/mbimbf.inc @@ -398,10 +398,10 @@ my $warn = ''; $SIG{__WARN__} = sub { $warn = shift; }; # these should warn, since '3.17' is a NaN in BigInt and thus >= returns undef $warn = ''; eval "\$z = 3.17 <= \$y"; ok ($z, 1); print "# Got: '$warn'\n" unless -ok ($warn =~ /^Use of uninitialized value (in numeric le \(<=\) |)at/); +ok ($warn =~ /^Use of uninitialized value (\$y )?(in numeric le \(<=\) |)at/); $warn = ''; eval "\$z = \$y >= 3.17"; ok ($z, 1); print "# Got: '$warn'\n" unless -ok ($warn =~ /^Use of uninitialized value (in numeric ge \(>=\) |)at/); +ok ($warn =~ /^Use of uninitialized value (\$y )?(in numeric ge \(>=\) |)at/); # XXX TODO breakage: # $z = $y->copy()->bmul($u,2,0,'odd'); ok ($z,31000); diff --git a/lib/Tie/RefHash.t b/lib/Tie/RefHash.t index 52e3a2d..55fde14 100644 --- a/lib/Tie/RefHash.t +++ b/lib/Tie/RefHash.t @@ -208,6 +208,7 @@ sub runtests { s/ at .+ line \d+\.$//mg; s/ at .+ line \d+, at .*//mg; s/ at .+ line \d+, near .*//mg; + s/(uninitialized value)( within)? [\$@%].*? in /$1 in /g; } my (@warnings, %seen); diff --git a/lib/charnames.t b/lib/charnames.t index 34fe56d..3502b74 100644 --- a/lib/charnames.t +++ b/lib/charnames.t @@ -399,7 +399,7 @@ Only HASH reference supported as argument to :alias at use charnames ":short", ":alias" => { e_ACUTE => "LATIN:e WITH ACUTE", "a_ACUTE" }; "Here: \N{e_ACUTE}\N{a_ACUTE}!\n"; EXPECT -Use of uninitialized value in string eq at +Use of uninitialized value ######## # alias with hashref two aliases use charnames ":short", ":alias" => { diff --git a/mg.c b/mg.c index d86e22d..d162cd3 100644 --- a/mg.c +++ b/mg.c @@ -491,12 +491,12 @@ Perl_magic_len(pTHX_ SV *sv, MAGIC *mg) } else { if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); } } else { if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); } return 0; case '+': diff --git a/perl.h b/perl.h index 7b9a51a..1ee4756 100644 --- a/perl.h +++ b/perl.h @@ -3237,7 +3237,7 @@ START_EXTERN_C /* handy constants */ EXTCONST char PL_warn_uninit[] - INIT("Use of uninitialized value%s%s"); + INIT("Use of uninitialized value%s%s%s"); EXTCONST char PL_warn_nosemi[] INIT("Semicolon seems to be missing"); EXTCONST char PL_warn_reserved[] diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 94fc189..923d0ab 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -4388,13 +4388,14 @@ arguments. See L. defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables. -To help you figure out what was undefined, perl tells you what operation -you used the undefined value in. Note, however, that perl optimizes your -program and the operation displayed in the warning may not necessarily -appear literally in your program. For example, C<"that $foo"> is -usually optimized into C<"that " . $foo>, and the warning will refer to -the C operator, even though there is no C<.> in your -program. +To help you figure out what was undefined, perl will try to tell you the +name of the variable (if any) that was undefined. In some cases it cannot +do this, so it also tells you what operation you used the undefined value +in. Note, however, that perl optimizes your program and the operation +displayed in the warning may not necessarily appear literally in your +program. For example, C<"that $foo"> is usually optimized into C<"that " +. $foo>, and the warning will refer to the C operator, +even though there is no C<.> in your program. =item Using a hash as a reference is deprecated diff --git a/pod/perlintern.pod b/pod/perlintern.pod index e12c271..e799231 100644 --- a/pod/perlintern.pod +++ b/pod/perlintern.pod @@ -791,11 +791,32 @@ Found in file pp.h =over 8 +=item find_uninit_var + +Find the name of the undefined variable (if any) that caused the operator o +to issue a "Use of uninitialized value" warning. +If match is true, only return a name if it's value matches uninit_sv. +So roughly speaking, if a unary operator (such as OP_COS) generates a +warning, then following the direct child of the op may yield an +OP_PADSV or OP_GV that gives the name of the undefined variable. On the +other hand, with OP_ADD there are two branches to follow, so we only print +the variable name if we get an exact match. + +The name is returned as a mortal SV. + +Assumes that PL_op is the op that originally triggered the error, and that +PL_comppad/PL_curpad points to the currently executing pad. + + SV* find_uninit_var(OP* obase, SV* uninit_sv, bool top) + +=for hackers +Found in file sv.c + =item report_uninit Print appropriate "Use of uninitialized variable" warning - void report_uninit() + void report_uninit(SV* uninit_sv) =for hackers Found in file sv.c diff --git a/pp.c b/pp.c index 0bf02fa..6a17ece 100644 --- a/pp.c +++ b/pp.c @@ -177,7 +177,7 @@ PP(pp_rv2gv) PL_op->op_private & HINT_STRICT_REFS) DIE(aTHX_ PL_no_usym, "a symbol"); if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); RETSETUNDEF; } sym = SvPV(sv,len); @@ -238,7 +238,7 @@ PP(pp_rv2sv) PL_op->op_private & HINT_STRICT_REFS) DIE(aTHX_ PL_no_usym, "a SCALAR"); if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); RETSETUNDEF; } sym = SvPV(sv, len); diff --git a/pp_hot.c b/pp_hot.c index 452c3a9..d02bf96 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -725,7 +725,7 @@ PP(pp_rv2av) PL_op->op_private & HINT_STRICT_REFS) DIE(aTHX_ PL_no_usym, "an ARRAY"); if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); if (GIMME == G_ARRAY) { (void)POPs; RETURN; @@ -856,7 +856,7 @@ PP(pp_rv2hv) PL_op->op_private & HINT_STRICT_REFS) DIE(aTHX_ PL_no_usym, "a HASH"); if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); if (gimme == G_ARRAY) { SP--; RETURN; diff --git a/proto.h b/proto.h index b72fede..9dcf1c8 100644 --- a/proto.h +++ b/proto.h @@ -805,7 +805,7 @@ PERL_CALLCONV U32 Perl_parse_unicode_opts(pTHX_ char **popt); PERL_CALLCONV U32 Perl_seed(pTHX); PERL_CALLCONV UV Perl_get_hash_seed(pTHX); PERL_CALLCONV void Perl_report_evil_fh(pTHX_ GV *gv, IO *io, I32 op); -PERL_CALLCONV void Perl_report_uninit(pTHX); +PERL_CALLCONV void Perl_report_uninit(pTHX_ SV* uninit_sv); PERL_CALLCONV void Perl_warn(pTHX_ const char* pat, ...) __attribute__format__(__printf__,pTHX_1,pTHX_2); PERL_CALLCONV void Perl_vwarn(pTHX_ const char* pat, va_list* args); @@ -1344,6 +1344,9 @@ PERL_CALLCONV void Perl_hv_clear_placeholders(pTHX_ HV* hb); PERL_CALLCONV SV* Perl_hv_scalar(pTHX_ HV* hv); PERL_CALLCONV SV* Perl_magic_scalarpack(pTHX_ HV* hv, MAGIC* mg); +#ifdef PERL_IN_SV_C +STATIC SV* S_find_uninit_var(pTHX_ OP* obase, SV* uninit_sv, bool top); +#endif #ifdef PERL_NEED_MY_HTOLE16 PERL_CALLCONV U16 Perl_my_htole16(U16 n); diff --git a/sv.c b/sv.c index c4aa66c..5e4bf72 100644 --- a/sv.c +++ b/sv.c @@ -602,6 +602,458 @@ Perl_sv_free_arenas(pTHX) PL_sv_root = 0; } +/* --------------------------------------------------------------------- + * + * support functions for report_uninit() + */ + +/* the maxiumum size of array or hash where we will scan looking + * for the undefined element that triggered the warning */ + +#define FUV_MAX_SEARCH_SIZE 1000 + +/* Look for an entry in the hash whose value has the same SV as val; + * If so, return a mortal copy of the key. */ + +STATIC SV* +S_find_hash_subscript(pTHX_ HV *hv, SV* val) +{ + register HE **array; + register HE *entry; + I32 i; + + if (!hv || SvMAGICAL(hv) || !HvARRAY(hv) || + (HvTOTALKEYS(hv) > FUV_MAX_SEARCH_SIZE)) + return Nullsv; + + array = HvARRAY(hv); + + for (i=HvMAX(hv); i>0; i--) { + for (entry = array[i]; entry; entry = HeNEXT(entry)) { + if (HeVAL(entry) != val) + continue; + if ( HeVAL(entry) == &PL_sv_undef || + HeVAL(entry) == &PL_sv_placeholder) + continue; + if (!HeKEY(entry)) + return Nullsv; + if (HeKLEN(entry) == HEf_SVKEY) + return sv_mortalcopy(HeKEY_sv(entry)); + return sv_2mortal(newSVpvn(HeKEY(entry), HeKLEN(entry))); + } + } + return Nullsv; +} + +/* Look for an entry in the array whose value has the same SV as val; + * If so, return the index, otherwise return -1. */ + +STATIC I32 +S_find_array_subscript(pTHX_ AV *av, SV* val) +{ + SV** svp; + I32 i; + if (!av || SvMAGICAL(av) || !AvARRAY(av) || + (AvFILLp(av) > FUV_MAX_SEARCH_SIZE)) + return -1; + + svp = AvARRAY(av); + for (i=AvFILLp(av); i>=0; i--) { + if (svp[i] == val && svp[i] != &PL_sv_undef) + return i; + } + return -1; +} + +/* S_varname(): return the name of a variable, optionally with a subscript. + * If gv is non-zero, use the name of that global, along with gvtype (one + * of "$", "@", "%"); otherwise use the name of the lexical at pad offset + * targ. Depending on the value of the subscript_type flag, return: + */ + +#define FUV_SUBSCRIPT_NONE 1 /* "@foo" */ +#define FUV_SUBSCRIPT_ARRAY 2 /* "$foo[aindex]" */ +#define FUV_SUBSCRIPT_HASH 3 /* "$foo{keyname}" */ +#define FUV_SUBSCRIPT_WITHIN 4 /* "within @foo" */ + +STATIC SV* +S_varname(pTHX_ GV *gv, char *gvtype, PADOFFSET targ, + SV* keyname, I32 aindex, int subscript_type) +{ + AV *av; + + SV *sv, *name; + + name = sv_newmortal(); + if (gv) { + + /* simulate gv_fullname4(), but add literal '^' for $^FOO names + * XXX get rid of all this if gv_fullnameX() ever supports this + * directly */ + + char *p; + HV *hv = GvSTASH(gv); + sv_setpv(name, gvtype); + if (!hv) + p = "???"; + else if (!HvNAME(hv)) + p = "__ANON__"; + else + p = HvNAME(hv); + if (strNE(p, "main")) { + sv_catpv(name,p); + sv_catpvn(name,"::", 2); + } + if (GvNAMELEN(gv)>= 1 && + ((unsigned int)*GvNAME(gv)) <= 26) + { /* handle $^FOO */ + Perl_sv_catpvf(aTHX_ name,"^%c", *GvNAME(gv) + 'A' - 1); + sv_catpvn(name,GvNAME(gv)+1,GvNAMELEN(gv)-1); + } + else + sv_catpvn(name,GvNAME(gv),GvNAMELEN(gv)); + } + else { + U32 u; + CV *cv = find_runcv(&u); + if (!cv || !CvPADLIST(cv)) + return Nullsv;; + av = (AV*)(*av_fetch(CvPADLIST(cv), 0, FALSE)); + sv = *av_fetch(av, targ, FALSE); + /* SvLEN in a pad name is not to be trusted */ + sv_setpv(name, SvPV_nolen(sv)); + } + + if (subscript_type == FUV_SUBSCRIPT_HASH) { + *SvPVX(name) = '$'; + sv = NEWSV(0,0); + Perl_sv_catpvf(aTHX_ name, "{%s}", + pv_display(sv,SvPVX(keyname), SvCUR(keyname), 0, 32)); + SvREFCNT_dec(sv); + } + else if (subscript_type == FUV_SUBSCRIPT_ARRAY) { + *SvPVX(name) = '$'; + Perl_sv_catpvf(aTHX_ name, "[%"IVdf"]", aindex); + } + else if (subscript_type == FUV_SUBSCRIPT_WITHIN) + sv_insert(name, 0, 0, "within ", 7); + + return name; +} + + +/* +=for apidoc find_uninit_var + +Find the name of the undefined variable (if any) that caused the operator o +to issue a "Use of uninitialized value" warning. +If match is true, only return a name if it's value matches uninit_sv. +So roughly speaking, if a unary operator (such as OP_COS) generates a +warning, then following the direct child of the op may yield an +OP_PADSV or OP_GV that gives the name of the undefined variable. On the +other hand, with OP_ADD there are two branches to follow, so we only print +the variable name if we get an exact match. + +The name is returned as a mortal SV. + +Assumes that PL_op is the op that originally triggered the error, and that +PL_comppad/PL_curpad points to the currently executing pad. + +=cut +*/ + +STATIC SV * +S_find_uninit_var(pTHX_ OP* obase, SV* uninit_sv, bool match) +{ + SV *sv; + AV *av; + SV **svp; + GV *gv; + OP *o, *o2, *kid; + + if (!obase || (match && (!uninit_sv || uninit_sv == &PL_sv_undef || + uninit_sv == &PL_sv_placeholder))) + return Nullsv; + + switch (obase->op_type) { + + case OP_RV2AV: + case OP_RV2HV: + case OP_PADAV: + case OP_PADHV: + { + bool pad = (obase->op_type == OP_PADAV || obase->op_type == OP_PADHV); + bool hash = (obase->op_type == OP_PADHV || obase->op_type == OP_RV2HV); + I32 index; + SV *keysv; + int subscript_type = FUV_SUBSCRIPT_WITHIN; + + if (pad) { /* @lex, %lex */ + sv = PAD_SVl(obase->op_targ); + gv = Nullgv; + } + else { + if (cUNOPx(obase)->op_first->op_type == OP_GV) { + /* @global, %global */ + gv = cGVOPx_gv(cUNOPx(obase)->op_first); + if (!gv) + break; + sv = hash ? (SV*)GvHV(gv): (SV*)GvAV(gv); + } + else /* @{expr}, %{expr} */ + return find_uninit_var(cUNOPx(obase)->op_first, + uninit_sv, match); + } + + /* attempt to find a match within the aggregate */ + if (hash) { + keysv = S_find_hash_subscript(aTHX_ (HV*)sv, uninit_sv); + if (keysv) + subscript_type = FUV_SUBSCRIPT_HASH; + } + else { + index = S_find_array_subscript(aTHX_ (AV*)sv, uninit_sv); + if (index >= 0) + subscript_type = FUV_SUBSCRIPT_ARRAY; + } + + if (match && subscript_type == FUV_SUBSCRIPT_WITHIN) + break; + + return S_varname(aTHX_ gv, hash ? "%" : "@", obase->op_targ, + keysv, index, subscript_type); + } + + case OP_PADSV: + if (match && PAD_SVl(obase->op_targ) != uninit_sv) + break; + return S_varname(aTHX_ Nullgv, "$", obase->op_targ, + Nullsv, 0, FUV_SUBSCRIPT_NONE); + + case OP_GVSV: + gv = cGVOPx_gv(obase); + if (!gv || (match && GvSV(gv) != uninit_sv)) + break; + return S_varname(aTHX_ gv, "$", 0, Nullsv, 0, FUV_SUBSCRIPT_NONE); + + case OP_AELEMFAST: + if (obase->op_flags & OPf_SPECIAL) { /* lexical array */ + if (match) { + av = (AV*)PAD_SV(obase->op_targ); + if (!av || SvRMAGICAL(av)) + break; + svp = av_fetch(av, (I32)obase->op_private, FALSE); + if (!svp || *svp != uninit_sv) + break; + } + return S_varname(aTHX_ Nullgv, "$", obase->op_targ, + Nullsv, (I32)obase->op_private, FUV_SUBSCRIPT_ARRAY); + } + else { + gv = cGVOPx_gv(obase); + if (!gv) + break; + if (match) { + av = GvAV(gv); + if (!av || SvRMAGICAL(av)) + break; + svp = av_fetch(av, (I32)obase->op_private, FALSE); + if (!svp || *svp != uninit_sv) + break; + } + return S_varname(aTHX_ gv, "$", 0, + Nullsv, (I32)obase->op_private, FUV_SUBSCRIPT_ARRAY); + } + break; + + case OP_EXISTS: + o = cUNOPx(obase)->op_first; + if (!o || o->op_type != OP_NULL || + ! (o->op_targ == OP_AELEM || o->op_targ == OP_HELEM)) + break; + return find_uninit_var(cBINOPo->op_last, uninit_sv, match); + + case OP_AELEM: + case OP_HELEM: + if (PL_op == obase) + /* $a[uninit_expr] or $h{uninit_expr} */ + return find_uninit_var(cBINOPx(obase)->op_last, uninit_sv, match); + + gv = Nullgv; + o = cBINOPx(obase)->op_first; + kid = cBINOPx(obase)->op_last; + + /* get the av or hv, and optionally the gv */ + sv = Nullsv; + if (o->op_type == OP_PADAV || o->op_type == OP_PADHV) { + sv = PAD_SV(o->op_targ); + } + else if ((o->op_type == OP_RV2AV || o->op_type == OP_RV2HV) + && cUNOPo->op_first->op_type == OP_GV) + { + gv = cGVOPx_gv(cUNOPo->op_first); + if (!gv) + break; + sv = o->op_type == OP_RV2HV ? (SV*)GvHV(gv) : (SV*)GvAV(gv); + } + if (!sv) + break; + + if (kid && kid->op_type == OP_CONST && SvOK(cSVOPx_sv(kid))) { + /* index is constant */ + if (match) { + if (SvMAGICAL(sv)) + break; + if (obase->op_type == OP_HELEM) { + HE* he = hv_fetch_ent((HV*)sv, cSVOPx_sv(kid), 0, 0); + if (!he || HeVAL(he) != uninit_sv) + break; + } + else { + svp = av_fetch((AV*)sv, SvIV(cSVOPx_sv(kid)), FALSE); + if (!svp || *svp != uninit_sv) + break; + } + } + if (obase->op_type == OP_HELEM) + return S_varname(aTHX_ gv, "%", o->op_targ, + cSVOPx_sv(kid), 0, FUV_SUBSCRIPT_HASH); + else + return S_varname(aTHX_ gv, "@", o->op_targ, Nullsv, + SvIV(cSVOPx_sv(kid)), FUV_SUBSCRIPT_ARRAY); + ; + } + else { + /* index is an expression; + * attempt to find a match within the aggregate */ + if (obase->op_type == OP_HELEM) { + SV *keysv = S_find_hash_subscript(aTHX_ (HV*)sv, uninit_sv); + if (keysv) + return S_varname(aTHX_ gv, "%", o->op_targ, + keysv, 0, FUV_SUBSCRIPT_HASH); + } + else { + I32 index = S_find_array_subscript(aTHX_ (AV*)sv, uninit_sv); + if (index >= 0) + return S_varname(aTHX_ gv, "@", o->op_targ, + Nullsv, index, FUV_SUBSCRIPT_ARRAY); + } + if (match) + break; + return S_varname(aTHX_ gv, + (o->op_type == OP_PADAV || o->op_type == OP_RV2AV) + ? "@" : "%", + o->op_targ, Nullsv, 0, FUV_SUBSCRIPT_WITHIN); + } + + break; + + case OP_AASSIGN: + /* only examine RHS */ + return find_uninit_var(cBINOPx(obase)->op_first, uninit_sv, match); + + case OP_OPEN: + o = cUNOPx(obase)->op_first; + if (o->op_type == OP_PUSHMARK) + o = o->op_sibling; + + if (!o->op_sibling) { + /* one-arg version of open is highly magical */ + + if (o->op_type == OP_GV) { /* open FOO; */ + gv = cGVOPx_gv(o); + if (match && GvSV(gv) != uninit_sv) + break; + return S_varname(aTHX_ gv, "$", 0, + Nullsv, 0, FUV_SUBSCRIPT_NONE); + } + /* other possibilities not handled are: + * open $x; or open my $x; should return '${*$x}' + * open expr; should return '$'.expr ideally + */ + break; + } + goto do_op; + + /* ops where $_ may be an implicit arg */ + case OP_TRANS: + case OP_SUBST: + case OP_MATCH: + if ( !(obase->op_flags & OPf_STACKED)) { + if (uninit_sv == ((obase->op_private & OPpTARGET_MY) + ? PAD_SVl(obase->op_targ) + : DEFSV)) + { + sv = sv_newmortal(); + sv_setpv(sv, "$_"); + return sv; + } + } + goto do_op; + + case OP_PRTF: + case OP_PRINT: + /* skip filehandle as it can't produce 'undef' warning */ + o = cUNOPx(obase)->op_first; + if ((obase->op_flags & OPf_STACKED) && o->op_type == OP_PUSHMARK) + o = o->op_sibling->op_sibling; + goto do_op2; + + + case OP_CUSTOM: + case OP_ENTERSUB: + match = 1; /* XS or custom code could trigger random warnings */ + goto do_op; + + case OP_SCHOMP: + case OP_CHOMP: + if (SvROK(PL_rs) && uninit_sv == SvRV(PL_rs)) + return sv_2mortal(newSVpv("${$/}", 0)); + /* FALL THROUGH */ + + default: + do_op: + if (!(obase->op_flags & OPf_KIDS)) + break; + o = cUNOPx(obase)->op_first; + + do_op2: + if (!o) + break; + + /* if all except one arg are constant, or have no side-effects, + * or are optimized away, then it's unambiguous */ + o2 = Nullop; + for (kid=o; kid; kid = kid->op_sibling) { + if (kid && + ( (kid->op_type == OP_CONST && SvOK(cSVOPx_sv(kid))) + || (kid->op_type == OP_NULL && ! (kid->op_flags & OPf_KIDS)) + || (kid->op_type == OP_PUSHMARK) + ) + ) + continue; + if (o2) { /* more than one found */ + o2 = Nullop; + break; + } + o2 = kid; + } + if (o2) + return find_uninit_var(o2, uninit_sv, match); + + /* scan all args */ + while (o) { + sv = find_uninit_var(o, uninit_sv, 1); + if (sv) + return sv; + o = o->op_sibling; + } + break; + } + return Nullsv; +} + + /* =for apidoc report_uninit @@ -611,13 +1063,22 @@ Print appropriate "Use of uninitialized variable" warning */ void -Perl_report_uninit(pTHX) +Perl_report_uninit(pTHX_ SV* uninit_sv) { - if (PL_op) + if (PL_op) { + SV* varname; + if (uninit_sv) { + varname = find_uninit_var(PL_op, uninit_sv,0); + if (varname) + sv_insert(varname, 0, 0, " ", 1); + } Perl_warner(aTHX_ packWARN(WARN_UNINITIALIZED), PL_warn_uninit, - " in ", OP_DESC(PL_op)); + varname ? SvPV_nolen(varname) : "", + " in ", OP_DESC(PL_op)); + } else - Perl_warner(aTHX_ packWARN(WARN_UNINITIALIZED), PL_warn_uninit, "", ""); + Perl_warner(aTHX_ packWARN(WARN_UNINITIALIZED), PL_warn_uninit, + "", "", ""); } /* grab a new IV body from the free list, allocating more if necessary */ @@ -2091,7 +2552,7 @@ Perl_sv_2iv_flags(pTHX_ register SV *sv, I32 flags) if (!SvROK(sv)) { if (!(SvFLAGS(sv) & SVs_PADTMP)) { if (ckWARN(WARN_UNINITIALIZED) && !PL_localizing) - report_uninit(); + report_uninit(sv); } return 0; } @@ -2109,7 +2570,7 @@ Perl_sv_2iv_flags(pTHX_ register SV *sv, I32 flags) } if (SvREADONLY(sv) && !SvOK(sv)) { if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); return 0; } } @@ -2351,7 +2812,7 @@ Perl_sv_2iv_flags(pTHX_ register SV *sv, I32 flags) } } else { if (ckWARN(WARN_UNINITIALIZED) && !PL_localizing && !(SvFLAGS(sv) & SVs_PADTMP)) - report_uninit(); + report_uninit(sv); if (SvTYPE(sv) < SVt_IV) /* Typically the caller expects that sv_any is not NULL now. */ sv_upgrade(sv, SVt_IV); @@ -2399,7 +2860,7 @@ Perl_sv_2uv_flags(pTHX_ register SV *sv, I32 flags) if (!SvROK(sv)) { if (!(SvFLAGS(sv) & SVs_PADTMP)) { if (ckWARN(WARN_UNINITIALIZED) && !PL_localizing) - report_uninit(); + report_uninit(sv); } return 0; } @@ -2417,7 +2878,7 @@ Perl_sv_2uv_flags(pTHX_ register SV *sv, I32 flags) } if (SvREADONLY(sv) && !SvOK(sv)) { if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); return 0; } } @@ -2640,7 +3101,7 @@ Perl_sv_2uv_flags(pTHX_ register SV *sv, I32 flags) else { if (!(SvFLAGS(sv) & SVs_PADTMP)) { if (ckWARN(WARN_UNINITIALIZED) && !PL_localizing) - report_uninit(); + report_uninit(sv); } if (SvTYPE(sv) < SVt_IV) /* Typically the caller expects that sv_any is not NULL now. */ @@ -2687,7 +3148,7 @@ Perl_sv_2nv(pTHX_ register SV *sv) if (!SvROK(sv)) { if (!(SvFLAGS(sv) & SVs_PADTMP)) { if (ckWARN(WARN_UNINITIALIZED) && !PL_localizing) - report_uninit(); + report_uninit(sv); } return 0; } @@ -2705,7 +3166,7 @@ Perl_sv_2nv(pTHX_ register SV *sv) } if (SvREADONLY(sv) && !SvOK(sv)) { if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); return 0.0; } } @@ -2836,7 +3297,7 @@ Perl_sv_2nv(pTHX_ register SV *sv) } else { if (ckWARN(WARN_UNINITIALIZED) && !PL_localizing && !(SvFLAGS(sv) & SVs_PADTMP)) - report_uninit(); + report_uninit(sv); if (SvTYPE(sv) < SVt_NV) /* Typically the caller expects that sv_any is not NULL now. */ /* XXX Ilya implies that this is a bug in callers that assume this @@ -3016,7 +3477,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) if (!SvROK(sv)) { if (!(SvFLAGS(sv) & SVs_PADTMP)) { if (ckWARN(WARN_UNINITIALIZED) && !PL_localizing) - report_uninit(); + report_uninit(sv); } *lp = 0; return ""; @@ -3166,7 +3627,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) } if (SvREADONLY(sv) && !SvOK(sv)) { if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(); + report_uninit(sv); *lp = 0; return ""; } @@ -3226,7 +3687,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) else { if (ckWARN(WARN_UNINITIALIZED) && !PL_localizing && !(SvFLAGS(sv) & SVs_PADTMP)) - report_uninit(); + report_uninit(sv); *lp = 0; if (SvTYPE(sv) < SVt_PV) /* Typically the caller expects that sv_any is not NULL now. */ diff --git a/t/lib/warnings/1global b/t/lib/warnings/1global index 0af8022..9de457d 100644 --- a/t/lib/warnings/1global +++ b/t/lib/warnings/1global @@ -43,7 +43,7 @@ EXPECT $^W = 1 ; my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 4. +Use of uninitialized value $b in scalar chop at - line 4. ######## # warnings enabled at compile time, disabled at run time @@ -59,7 +59,7 @@ BEGIN { $^W = 0 } $^W = 1 ; my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 5. +Use of uninitialized value $b in scalar chop at - line 5. ######## -w --FILE-- abcd @@ -68,7 +68,7 @@ my $b ; chop $b ; --FILE-- require "./abcd"; EXPECT -Use of uninitialized value in scalar chop at ./abcd line 1. +Use of uninitialized value $b in scalar chop at ./abcd line 1. ######## --FILE-- abcd @@ -78,7 +78,7 @@ my $b ; chop $b ; #! perl -w require "./abcd"; EXPECT -Use of uninitialized value in scalar chop at ./abcd line 1. +Use of uninitialized value $b in scalar chop at ./abcd line 1. ######## --FILE-- abcd @@ -88,7 +88,7 @@ my $b ; chop $b ; $^W =1 ; require "./abcd"; EXPECT -Use of uninitialized value in scalar chop at ./abcd line 1. +Use of uninitialized value $b in scalar chop at ./abcd line 1. ######## --FILE-- abcd @@ -110,28 +110,28 @@ $^W =0 ; require "./abcd"; my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $b in scalar chop at - line 3. ######## $^W = 1; eval 'my $b ; chop $b ;' ; print $@ ; EXPECT -Use of uninitialized value in scalar chop at (eval 1) line 1. +Use of uninitialized value $b in scalar chop at (eval 1) line 1. ######## eval '$^W = 1;' ; print $@ ; my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 4. +Use of uninitialized value $b in scalar chop at - line 4. ######## eval {$^W = 1;} ; print $@ ; my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 4. +Use of uninitialized value $b in scalar chop at - line 4. ######## { @@ -149,7 +149,7 @@ my $a ; chop $a ; } my $c ; chop $c ; EXPECT -Use of uninitialized value in scalar chop at - line 5. +Use of uninitialized value $b in scalar chop at - line 5. ######## -w -e undef @@ -186,4 +186,4 @@ sub fred { my $b ; chop $b ;} fred() ; } EXPECT -Use of uninitialized value in scalar chop at - line 2. +Use of uninitialized value $b in scalar chop at - line 2. diff --git a/t/lib/warnings/2use b/t/lib/warnings/2use index b700ef7..7810287 100644 --- a/t/lib/warnings/2use +++ b/t/lib/warnings/2use @@ -42,7 +42,7 @@ use warnings 'uninitialized' ; } my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 8. +Use of uninitialized value $b in scalar chop at - line 8. ######## # Check runtime scope of pragma @@ -53,7 +53,7 @@ no warnings ; } my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## # Check runtime scope of pragma @@ -64,7 +64,7 @@ no warnings ; } &$a ; EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## use warnings 'syntax' ; @@ -103,7 +103,7 @@ require "./abc"; my $a ; chop $a ; EXPECT Reversed += operator at ./abc line 2. -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $a in scalar chop at - line 3. ######## --FILE-- abc.pm @@ -116,7 +116,7 @@ use abc; my $a ; chop $a ; EXPECT Reversed += operator at abc.pm line 2. -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $a in scalar chop at - line 3. ######## # Check scope of pragma with eval @@ -143,7 +143,7 @@ use warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at - line 8. +Use of uninitialized value $b in scalar chop at - line 8. ######## # Check scope of pragma with eval @@ -156,8 +156,8 @@ no warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at - line 7. -Use of uninitialized value in scalar chop at - line 9. +Use of uninitialized value $b in scalar chop at - line 7. +Use of uninitialized value $b in scalar chop at - line 9. ######## # Check scope of pragma with eval @@ -171,7 +171,7 @@ no warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at - line 10. +Use of uninitialized value $b in scalar chop at - line 10. ######## # Check scope of pragma with eval @@ -253,7 +253,7 @@ use warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at (eval 1) line 3. +Use of uninitialized value $b in scalar chop at (eval 1) line 3. ######## # Check scope of pragma with eval @@ -266,8 +266,8 @@ no warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at (eval 1) line 2. -Use of uninitialized value in scalar chop at - line 9. +Use of uninitialized value $b in scalar chop at (eval 1) line 2. +Use of uninitialized value $b in scalar chop at - line 9. ######## # Check scope of pragma with eval @@ -281,7 +281,7 @@ no warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at - line 10. +Use of uninitialized value $b in scalar chop at - line 10. ######## # Check scope of pragma with eval @@ -351,4 +351,4 @@ no warnings 'syntax' ; $a =+ 1 ; EXPECT Reversed += operator at - line 6. -Use of uninitialized value in scalar chop at - line 9. +Use of uninitialized value $c in scalar chop at - line 9. diff --git a/t/lib/warnings/3both b/t/lib/warnings/3both index a4d9ba8..733261c 100644 --- a/t/lib/warnings/3both +++ b/t/lib/warnings/3both @@ -13,7 +13,7 @@ sub fred { } EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## # Check interaction of $^W and use warnings @@ -27,7 +27,7 @@ sub fred { } EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## # Check interaction of $^W and use warnings @@ -64,7 +64,7 @@ $^W = 1 ; my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## # Check interaction of $^W and use warnings @@ -73,7 +73,7 @@ use warnings ; my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## # Check interaction of $^W and use warnings @@ -107,7 +107,7 @@ use warnings ; my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 5. +Use of uninitialized value $b in scalar chop at - line 5. ######## # Check interaction of $^W and use warnings @@ -119,7 +119,7 @@ sub fred { BEGIN { $^W = 0 } fred() ; EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## # Check interaction of $^W and use warnings @@ -141,7 +141,7 @@ BEGIN { $^W = 1 } my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## # Check interaction of $^W and use warnings @@ -150,7 +150,7 @@ use warnings ; my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## # Check interaction of $^W and use warnings @@ -181,7 +181,7 @@ BEGIN { $^W = 1 } my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 10. +Use of uninitialized value $b in scalar chop at - line 10. ######## # Check interaction of $^W and use warnings @@ -194,7 +194,7 @@ BEGIN { $^W = 0 } my $b ; chop $b ; EXPECT -Use of uninitialized value in scalar chop at - line 7. +Use of uninitialized value $b in scalar chop at - line 7. ######## # Check scope of pragma with eval @@ -222,7 +222,7 @@ use warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at (eval 1) line 3. +Use of uninitialized value $b in scalar chop at (eval 1) line 3. ######## # Check scope of pragma with eval @@ -235,8 +235,8 @@ BEGIN { $^W = 0 } my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at (eval 1) line 2. -Use of uninitialized value in scalar chop at - line 9. +Use of uninitialized value $b in scalar chop at (eval 1) line 2. +Use of uninitialized value $b in scalar chop at - line 9. ######## # Check scope of pragma with eval @@ -250,7 +250,7 @@ BEGIN { $^W = 0 } my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at - line 10. +Use of uninitialized value $b in scalar chop at - line 10. ######## # Check scope of pragma with eval diff --git a/t/lib/warnings/4lint b/t/lib/warnings/4lint index 805bd98..5b46ce4 100644 --- a/t/lib/warnings/4lint +++ b/t/lib/warnings/4lint @@ -68,7 +68,7 @@ use abc; my $a ; chop $a ; EXPECT Reversed += operator at abc.pm line 4. -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $a in scalar chop at - line 3. ######## -W --FILE-- abc @@ -83,7 +83,7 @@ require "./abc"; my $a ; chop $a ; EXPECT Reversed += operator at ./abc line 4. -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $a in scalar chop at - line 3. ######## -W --FILE-- abc.pm @@ -98,7 +98,7 @@ use abc; my $a ; chop $a ; EXPECT Reversed += operator at abc.pm line 4. -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $a in scalar chop at - line 3. ######## -W --FILE-- abc @@ -112,7 +112,7 @@ require "./abc"; my $a ; chop $a ; EXPECT Reversed += operator at ./abc line 3. -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $a in scalar chop at - line 3. ######## -W # Check scope of pragma with eval @@ -124,8 +124,8 @@ Use of uninitialized value in scalar chop at - line 3. my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at (eval 1) line 2. -Use of uninitialized value in scalar chop at - line 8. +Use of uninitialized value $b in scalar chop at (eval 1) line 2. +Use of uninitialized value $b in scalar chop at - line 8. ######## -W # Check scope of pragma with eval @@ -139,8 +139,8 @@ use warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at (eval 1) line 3. -Use of uninitialized value in scalar chop at - line 10. +Use of uninitialized value $b in scalar chop at (eval 1) line 3. +Use of uninitialized value $b in scalar chop at - line 10. ######## -W # Check scope of pragma with eval @@ -153,8 +153,8 @@ no warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at (eval 1) line 2. -Use of uninitialized value in scalar chop at - line 9. +Use of uninitialized value $b in scalar chop at (eval 1) line 2. +Use of uninitialized value $b in scalar chop at - line 9. ######## -W # Check scope of pragma with eval @@ -168,8 +168,8 @@ no warnings; my $b ; chop $b ; } EXPECT -Use of uninitialized value in scalar chop at (eval 1) line 3. -Use of uninitialized value in scalar chop at - line 10. +Use of uninitialized value $b in scalar chop at (eval 1) line 3. +Use of uninitialized value $b in scalar chop at - line 10. ######## -W # Check scope of pragma with eval diff --git a/t/lib/warnings/7fatal b/t/lib/warnings/7fatal index a3e70f8..1ad7658 100644 --- a/t/lib/warnings/7fatal +++ b/t/lib/warnings/7fatal @@ -35,7 +35,7 @@ use warnings FATAL => 'uninitialized' ; my $b ; chop $b ; print STDERR "The End.\n" ; EXPECT -Use of uninitialized value in scalar chop at - line 8. +Use of uninitialized value $b in scalar chop at - line 8. ######## # Check runtime scope of pragma @@ -47,7 +47,7 @@ use warnings FATAL => 'all' ; my $b ; chop $b ; print STDERR "The End.\n" ; EXPECT -Use of uninitialized value in scalar chop at - line 8. +Use of uninitialized value $b in scalar chop at - line 8. ######## # Check runtime scope of pragma @@ -59,7 +59,7 @@ no warnings ; &$a ; print STDERR "The End.\n" ; EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## # Check runtime scope of pragma @@ -71,7 +71,7 @@ no warnings ; &$a ; print STDERR "The End.\n" ; EXPECT -Use of uninitialized value in scalar chop at - line 6. +Use of uninitialized value $b in scalar chop at - line 6. ######## --FILE-- abc @@ -105,7 +105,7 @@ my $a ; chop $a ; print STDERR "The End.\n" ; EXPECT Reversed += operator at ./abc line 2. -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $a in scalar chop at - line 3. ######## --FILE-- abc.pm @@ -119,7 +119,7 @@ my $a ; chop $a ; print STDERR "The End.\n" ; EXPECT Reversed += operator at abc.pm line 2. -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $a in scalar chop at - line 3. ######## # Check scope of pragma with eval @@ -131,7 +131,7 @@ eval { my $b ; chop $b ; print STDERR "The End.\n" ; EXPECT --- Use of uninitialized value in scalar chop at - line 6. +-- Use of uninitialized value $b in scalar chop at - line 6. The End. ######## @@ -143,8 +143,8 @@ eval { my $b ; chop $b ; print STDERR "The End.\n" ; EXPECT --- Use of uninitialized value in scalar chop at - line 5. -Use of uninitialized value in scalar chop at - line 7. +-- Use of uninitialized value $b in scalar chop at - line 5. +Use of uninitialized value $b in scalar chop at - line 7. ######## # Check scope of pragma with eval @@ -156,7 +156,7 @@ eval { my $b ; chop $b ; print STDERR "The End.\n" ; EXPECT -Use of uninitialized value in scalar chop at - line 8. +Use of uninitialized value $b in scalar chop at - line 8. ######## # Check scope of pragma with eval @@ -214,7 +214,7 @@ eval q[ my $b ; chop $b ; print STDERR "The End.\n" ; EXPECT --- Use of uninitialized value in scalar chop at (eval 1) line 3. +-- Use of uninitialized value $b in scalar chop at (eval 1) line 3. The End. ######## @@ -226,8 +226,8 @@ eval ' my $b ; chop $b ; print STDERR "The End.\n" ; EXPECT --- Use of uninitialized value in scalar chop at (eval 1) line 2. -Use of uninitialized value in scalar chop at - line 7. +-- Use of uninitialized value $b in scalar chop at (eval 1) line 2. +Use of uninitialized value $b in scalar chop at - line 7. ######## # Check scope of pragma with eval @@ -239,7 +239,7 @@ eval ' my $b ; chop $b ; print STDERR "The End.\n" ; EXPECT -Use of uninitialized value in scalar chop at - line 8. +Use of uninitialized value $b in scalar chop at - line 8. ######## # Check scope of pragma with eval @@ -324,8 +324,8 @@ use warnings FATAL => 'all'; my $b ; chop $b; print STDERR "The End.\n" ; EXPECT -Use of uninitialized value in scalar chop at - line 8. -Use of uninitialized value in scalar chop at - line 11. +Use of uninitialized value $b in scalar chop at - line 8. +Use of uninitialized value $b in scalar chop at - line 11. ######## use warnings FATAL => 'all'; @@ -340,8 +340,8 @@ use warnings FATAL => 'all'; my $b ; chop $b; print STDERR "The End.\n" ; EXPECT -Use of uninitialized value in scalar chop at - line 8. -Use of uninitialized value in scalar chop at - line 11. +Use of uninitialized value $b in scalar chop at - line 8. +Use of uninitialized value $b in scalar chop at - line 11. ######## use warnings FATAL => 'all'; @@ -355,7 +355,7 @@ use warnings FATAL => 'all'; my $b ; chop $b; print STDERR "The End.\n" ; EXPECT -Use of uninitialized value in scalar chop at - line 7. +Use of uninitialized value $b in scalar chop at - line 7. ######## use warnings FATAL => 'syntax', NONFATAL => 'void' ; @@ -383,7 +383,7 @@ length "abc"; print STDERR "The End.\n" ; EXPECT Useless use of length in void context at - line 5. -Use of uninitialized value in scalar chomp at - line 4. +Use of uninitialized value $a in scalar chomp at - line 4. ######## use warnings FATAL => 'void', NONFATAL => 'void' ; diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit new file mode 100644 index 0000000..67139c3 --- /dev/null +++ b/t/lib/warnings/9uninit @@ -0,0 +1,1288 @@ +DAPM 4/2004. + +Test the appearance of variable names in "Use of uninitialized value" +warnings. + +The following ops aren't tested, mainly because they do IO or non-portable +stuff: + + send recv bind conect listen accept shutdown chdir chown chroot unlink + chmod utime rename link symlink readlink mkdir rmdir opendir seekdir + system exec kill getpgrp alarm sleep dofile require gethostbyname + gethostbyaddr getnetbyname getnetbyaddr getprotobyname getprotobynumber + getservbyname getservbyport sethostent setnetent setprotoent setservent + getpwnam getpwuid getgrnam getgrgid waitpid setpgrp setpriority + getpriority syscall dbmopen ioctl fcntl truncate getsockopt setsockopt + semctl semop semget msgget msgctl msgsnd msgrcv shmget shmctl shmread + shmwrite + + --------------------------------------------------- + + +__END__ +use warnings 'uninitialized'; +my ($m1, $m2, $v); + +$v = $m1 + 10; +$v = 22 + $m2; +$v = $m1 + $m2; +EXPECT +Use of uninitialized value $m1 in addition (+) at - line 4. +Use of uninitialized value $m2 in addition (+) at - line 5. +Use of uninitialized value $m2 in addition (+) at - line 6. +Use of uninitialized value $m1 in addition (+) at - line 6. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1, $g2); + +$v = $g1 + 21; +$v = 31 + $g2; +$v = $g1 + $g2; +$v = $m1 + $g2; +EXPECT +Use of uninitialized value $g1 in addition (+) at - line 5. +Use of uninitialized value $g2 in addition (+) at - line 6. +Use of uninitialized value $g2 in addition (+) at - line 7. +Use of uninitialized value $g1 in addition (+) at - line 7. +Use of uninitialized value $g2 in addition (+) at - line 8. +Use of uninitialized value $m1 in addition (+) at - line 8. +######## +use warnings 'uninitialized'; +my ($m1, @ma, $v); + +$v = $ma[5] + 45; +$v = 56 + $ma[6]; +$v = $ma[7] + $m1; +$v = $ma[8] + $ma[9]; +$v = $ma[-1] + $ma[-2]; +EXPECT +Use of uninitialized value $ma[5] in addition (+) at - line 4. +Use of uninitialized value $ma[6] in addition (+) at - line 5. +Use of uninitialized value $m1 in addition (+) at - line 6. +Use of uninitialized value in addition (+) at - line 6. +Use of uninitialized value in addition (+) at - line 7. +Use of uninitialized value in addition (+) at - line 7. +Use of uninitialized value in addition (+) at - line 8. +Use of uninitialized value in addition (+) at - line 8. +######## +use warnings 'uninitialized'; +my ($v); +my @mau = (undef) x 258; +my %mhu = ('foo', undef, 'bar', undef); + +$v = $mau[5] + 23; +$v = $mau[-5] + 45; +$v = 56 + $mau[6]; +$v = 78 + $mau[-6]; +$v = $mau[7] + $mau[8]; +$v = $mau[256] + $mau[257]; +$v = $mau[-1] + $mau[-2]; +$v = $mhu{foo} + $mhu{bar}; +EXPECT +Use of uninitialized value $mau[5] in addition (+) at - line 6. +Use of uninitialized value $mau[-5] in addition (+) at - line 7. +Use of uninitialized value $mau[6] in addition (+) at - line 8. +Use of uninitialized value $mau[-6] in addition (+) at - line 9. +Use of uninitialized value $mau[8] in addition (+) at - line 10. +Use of uninitialized value $mau[7] in addition (+) at - line 10. +Use of uninitialized value $mau[257] in addition (+) at - line 11. +Use of uninitialized value $mau[256] in addition (+) at - line 11. +Use of uninitialized value $mau[-2] in addition (+) at - line 12. +Use of uninitialized value $mau[-1] in addition (+) at - line 12. +Use of uninitialized value $mhu{"bar"} in addition (+) at - line 13. +Use of uninitialized value $mhu{"foo"} in addition (+) at - line 13. +######## +use warnings 'uninitialized'; +my ($v); +our (@ga); + +$v = $ga[8] + 21; +$v = $ga[-8] + 46; +$v = 57 + $ga[9]; +$v = 58 + $ga[-9]; +$v = $ga[10] + $ga[11]; +$v = $ga[-10] + $ga[-11]; +EXPECT +Use of uninitialized value $ga[8] in addition (+) at - line 5. +Use of uninitialized value $ga[-8] in addition (+) at - line 6. +Use of uninitialized value $ga[9] in addition (+) at - line 7. +Use of uninitialized value $ga[-9] in addition (+) at - line 8. +Use of uninitialized value in addition (+) at - line 9. +Use of uninitialized value in addition (+) at - line 9. +Use of uninitialized value in addition (+) at - line 10. +Use of uninitialized value in addition (+) at - line 10. +######## +use warnings 'uninitialized'; +my ($v); +our @gau = (undef) x 258; +our %ghu = ('foo', undef, 'bar', undef); + +$v = $gau[8] + 46; +$v = $gau[-8] + 47; +$v = 57 + $gau[9]; +$v = 57 + $gau[-9]; +$v = $gau[10] + $gau[11]; +$v = $gau[256] + $gau[257]; +$v = $gau[-1] + $gau[-2]; +$v = $ghu{foo} + $ghu{bar}; +EXPECT +Use of uninitialized value $gau[8] in addition (+) at - line 6. +Use of uninitialized value $gau[-8] in addition (+) at - line 7. +Use of uninitialized value $gau[9] in addition (+) at - line 8. +Use of uninitialized value $gau[-9] in addition (+) at - line 9. +Use of uninitialized value $gau[11] in addition (+) at - line 10. +Use of uninitialized value $gau[10] in addition (+) at - line 10. +Use of uninitialized value $gau[257] in addition (+) at - line 11. +Use of uninitialized value $gau[256] in addition (+) at - line 11. +Use of uninitialized value $gau[-2] in addition (+) at - line 12. +Use of uninitialized value $gau[-1] in addition (+) at - line 12. +Use of uninitialized value $ghu{"bar"} in addition (+) at - line 13. +Use of uninitialized value $ghu{"foo"} in addition (+) at - line 13. +######## +use warnings 'uninitialized'; +my ($v); +our @gau = (undef) x 258; +our %ghu = ('foo', undef, 'bar', undef); +my @mau = (undef) x 258; +my %mhu = ('foo', undef, 'bar', undef); + +my $i1 = 10; +my $i2 = 20; +my $i3 = 2000; +my $k1 = 'foo'; +my $k2 = 'bar'; +my $k3 = 'baz'; +$v = $mau[$i1] + $mau[$i2]; +$v = $gau[$i1] + $gau[$i2]; +$v = $gau[$i1] + $gau[$i3]; +$v = $mhu{$k1} + $mhu{$k2}; +$v = $ghu{$k1} + $ghu{$k2}; +$v = $ghu{$k1} + $ghu{$k3}; +EXPECT +Use of uninitialized value $mau[20] in addition (+) at - line 14. +Use of uninitialized value $mau[10] in addition (+) at - line 14. +Use of uninitialized value $gau[20] in addition (+) at - line 15. +Use of uninitialized value $gau[10] in addition (+) at - line 15. +Use of uninitialized value in addition (+) at - line 16. +Use of uninitialized value $gau[10] in addition (+) at - line 16. +Use of uninitialized value $mhu{"bar"} in addition (+) at - line 17. +Use of uninitialized value $mhu{"foo"} in addition (+) at - line 17. +Use of uninitialized value $ghu{"bar"} in addition (+) at - line 18. +Use of uninitialized value $ghu{"foo"} in addition (+) at - line 18. +Use of uninitialized value in addition (+) at - line 19. +Use of uninitialized value $ghu{"foo"} in addition (+) at - line 19. +######## +use warnings 'uninitialized'; +my ($m1, $m2, @ma, %mh, $v); +our ($g1, $g2, @ga, %gh); + +$v = $ma[$m1]; +$v = $ma[$g1]; +$v = $ga[$m2]; +$v = $ga[$g2]; + +$v = $mh{$m1}; +$v = $mh{$g1}; +$v = $gh{$m2}; +$v = $gh{$g2}; + +$v = $m1+($m2-$g1); +$v = $ma[$ga[3]]; +$v = $ga[$ma[4]]; +EXPECT +Use of uninitialized value $m1 in array element at - line 5. +Use of uninitialized value $g1 in array element at - line 6. +Use of uninitialized value $m2 in array element at - line 7. +Use of uninitialized value $g2 in array element at - line 8. +Use of uninitialized value $m1 in hash element at - line 10. +Use of uninitialized value $g1 in hash element at - line 11. +Use of uninitialized value $m2 in hash element at - line 12. +Use of uninitialized value $g2 in hash element at - line 13. +Use of uninitialized value $g1 in subtraction (-) at - line 15. +Use of uninitialized value $m2 in subtraction (-) at - line 15. +Use of uninitialized value $m1 in addition (+) at - line 15. +Use of uninitialized value $ga[3] in array element at - line 16. +Use of uninitialized value $ma[4] in array element at - line 17. +######## +use warnings 'uninitialized'; +my (@ma, %mh, $v); +our (@ga, %gh); + +$v = sin $ga[1000]; +$v = sin $ma[1000]; +$v = sin $gh{foo}; +$v = sin $mh{bar}; + +$v = sin $ga[$$]; +$v = sin $ma[$$]; +$v = sin $gh{$$}; +$v = sin $mh{$$}; +EXPECT +Use of uninitialized value $ga[1000] in sin at - line 5. +Use of uninitialized value $ma[1000] in sin at - line 6. +Use of uninitialized value $gh{"foo"} in sin at - line 7. +Use of uninitialized value $mh{"bar"} in sin at - line 8. +Use of uninitialized value within @ga in sin at - line 10. +Use of uninitialized value within @ma in sin at - line 11. +Use of uninitialized value within %gh in sin at - line 12. +Use of uninitialized value within %mh in sin at - line 13. +######## +use warnings 'uninitialized'; +my (@mat, %mht, $v); +sub X::TIEARRAY { bless [], 'X' } +sub X::TIEHASH { bless [], 'X' } +sub X::FETCH { undef } +tie @mat, 'X'; +tie %mht, 'X'; +my $key1 = 'akey'; +my $key2 = 'bkey'; +my $index1 = 33; +my $index2 = 55; + +$v = sin $mat[0]; +$v = $mat[0] + $mat[1]; +$v = sin $mat[1000]; +$v = $mat[1000] + $mat[1001]; + +$v = sin $mat[$index1]; +$v = $mat[$index1] + $mat[$index2]; + +$v = sin $mht{foo}; +$v = $mht{foo} + $mht{bar}; + +$v = sin $mht{$key1}; +$v = $mht{$key1} + $mht{$key2}; + +$v = $1+1; +EXPECT +Use of uninitialized value $mat[0] in sin at - line 13. +Use of uninitialized value in addition (+) at - line 14. +Use of uninitialized value in addition (+) at - line 14. +Use of uninitialized value $mat[1000] in sin at - line 15. +Use of uninitialized value in addition (+) at - line 16. +Use of uninitialized value in addition (+) at - line 16. +Use of uninitialized value within @mat in sin at - line 18. +Use of uninitialized value in addition (+) at - line 19. +Use of uninitialized value in addition (+) at - line 19. +Use of uninitialized value $mht{"foo"} in sin at - line 21. +Use of uninitialized value in addition (+) at - line 22. +Use of uninitialized value in addition (+) at - line 22. +Use of uninitialized value within %mht in sin at - line 24. +Use of uninitialized value in addition (+) at - line 25. +Use of uninitialized value in addition (+) at - line 25. +Use of uninitialized value $1 in addition (+) at - line 27. +######## +use warnings 'uninitialized'; +my ($m1); +our ($g1, @ga); + +print $ga[1000]; +print STDERR $ga[1000]; +print STDERR $m1, $g1, $ga[1],$m2; +print STDERR "", $ga[1],""; +EXPECT +Use of uninitialized value $ga[1000] in print at - line 5. +Use of uninitialized value $ga[1000] in print at - line 6. +Use of uninitialized value $m1 in print at - line 7. +Use of uninitialized value $g1 in print at - line 7. +Use of uninitialized value in print at - line 7. +Use of uninitialized value $m2 in print at - line 7. +Use of uninitialized value $ga[1] in print at - line 8. +######## +use warnings 'uninitialized'; +my ($m1); +our ($g1); + +close $m1; # exercises rv2gv +close $g1; # exercises rv2gv +EXPECT +Use of uninitialized value $m1 in ref-to-glob cast at - line 5. +Use of uninitialized value $g1 in ref-to-glob cast at - line 6. +######## +use warnings 'uninitialized'; +my ($m1, $m2, $v); +our ($g1, $g2); + +$v = $$m1; +$v = $$g1; + +$v = @$m1; +$v = @$g1; +$v = %$m2; +$v = %$g2; +EXPECT +Use of uninitialized value $m1 in scalar dereference at - line 5. +Use of uninitialized value $g1 in scalar dereference at - line 6. +Use of uninitialized value $m1 in array dereference at - line 8. +Use of uninitialized value $g1 in array dereference at - line 9. +Use of uninitialized value $m2 in hash dereference at - line 10. +Use of uninitialized value $g2 in hash dereference at - line 11. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +$v = $m1 | $m2; +$v = $m1 & $m2; +$v = $m1 ^ $m2; +$v = ~$m1; + +$v = $g1 | $g2; +$v = $g1 & $g2; +$v = $g1 ^ $g2; +$v = ~$g1; +EXPECT +Use of uninitialized value $m1 in bitwise or (|) at - line 5. +Use of uninitialized value $m2 in bitwise or (|) at - line 5. +Use of uninitialized value $m1 in bitwise and (&) at - line 6. +Use of uninitialized value $m2 in bitwise and (&) at - line 6. +Use of uninitialized value $m1 in bitwise xor (^) at - line 7. +Use of uninitialized value $m2 in bitwise xor (^) at - line 7. +Use of uninitialized value $m1 in 1's complement (~) at - line 8. +Use of uninitialized value $g1 in bitwise or (|) at - line 10. +Use of uninitialized value $g2 in bitwise or (|) at - line 10. +Use of uninitialized value $g1 in bitwise and (&) at - line 11. +Use of uninitialized value $g2 in bitwise and (&) at - line 11. +Use of uninitialized value $g1 in bitwise xor (^) at - line 12. +Use of uninitialized value $g2 in bitwise xor (^) at - line 12. +Use of uninitialized value $g1 in 1's complement (~) at - line 13. +######## +use warnings 'uninitialized'; +my ($v); + +my $tmp1; $v = $tmp1++; # (doesn't warn) +our $tmp2; $v = $tmp2++; # (doesn't warn) +my $tmp3; $v = ++$tmp1; # (doesn't warn) +our $tmp4; $v = ++$tmp2; # (doesn't warn) + +my $tmp5; $v = $tmp5--; # (doesn't warn) +our $tmp6; $v = $tmp6--; # (doesn't warn) +my $tmp7; $v = --$tmp7; # (doesn't warn) +our $tmp8; $v = --$tmp8; # (doesn't warn) +EXPECT +######## +use warnings 'uninitialized'; + +my $s1; chomp $s1; +my $s2; chop $s2; +my ($s3,$s4); chomp ($s3,$s4); +my ($s5,$s6); chop ($s5,$s6); +EXPECT +Use of uninitialized value $s1 in scalar chomp at - line 3. +Use of uninitialized value $s2 in scalar chop at - line 4. +Use of uninitialized value $s4 in chomp at - line 5. +Use of uninitialized value $s3 in chomp at - line 5. +Use of uninitialized value $s5 in chop at - line 6. +Use of uninitialized value $s6 in chop at - line 6. +######## +use warnings 'uninitialized'; +my ($m1); + +local $/ =\$m1; +my $x = "abc"; +chomp $x; chop $x; +my $y; +chomp ($x, $y); chop ($x, $y); +EXPECT +Use of uninitialized value ${$/} in scalar chomp at - line 6. +Use of uninitialized value ${$/} in chomp at - line 8. +Use of uninitialized value $y in chomp at - line 8. +Use of uninitialized value ${$/} in chomp at - line 8. +Use of uninitialized value $y in chop at - line 8. +######## +use warnings 'uninitialized'; +my ($m1, @ma, %mh); +our ($g1); + +delete $ma[$m1]; +delete @ma[$m1, $g1]; +delete $mh{$m1}; +delete @mh{$m1, $g1}; +EXPECT +Use of uninitialized value $m1 in delete at - line 5. +Use of uninitialized value $m1 in delete at - line 6. +Use of uninitialized value $g1 in delete at - line 6. +Use of uninitialized value $m1 in delete at - line 7. +Use of uninitialized value $m1 in delete at - line 8. +Use of uninitialized value $g1 in delete at - line 8. +######## +use warnings 'uninitialized'; +my ($m1, @ma, %mh); +our ($g1); + +my @a = @ma[$m1, $g1]; +@a = (4,5)[$m1, $g1]; +@a = @mh{$m1, $g1}; +EXPECT +Use of uninitialized value $m1 in array slice at - line 5. +Use of uninitialized value $g1 in array slice at - line 5. +Use of uninitialized value $m1 in list slice at - line 6. +Use of uninitialized value $g1 in list slice at - line 6. +Use of uninitialized value $m1 in hash slice at - line 7. +Use of uninitialized value $g1 in hash slice at - line 7. +######## +use warnings 'uninitialized'; +my ($m1, @ma, %mh, $v); +our ($g1, @ga, %gh); + +$v = exists $ma[$m1]; +$v = exists $ga[$g1]; +$v = exists $mh{$m1}; +$v = exists $gh{$g1}; +EXPECT +Use of uninitialized value $m1 in exists at - line 5. +Use of uninitialized value $g1 in exists at - line 6. +Use of uninitialized value $m1 in exists at - line 7. +Use of uninitialized value $g1 in exists at - line 8. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +my ($x1,$x2); +$v = $x1 << $m1; +$v = $x2 << $g1; +EXPECT +Use of uninitialized value $m1 in left bitshift (<<) at - line 6. +Use of uninitialized value $x1 in left bitshift (<<) at - line 6. +Use of uninitialized value $g1 in left bitshift (<<) at - line 7. +Use of uninitialized value $x2 in left bitshift (<<) at - line 7. +######## +use warnings 'uninitialized'; +my ($m1, $m2, $v); +our ($g1, $g2); + +use integer; +$v = $m1 + $g1; +$v = $m1 - $g1; +$v = $m1 * $g1; +eval {$v = $m1 / $g1}; +$v = $m2 / 2; +eval {$v = $m1 % $g1}; +$v = $m2 % 2; +$v = $m1 < $g1; +$v = $m1 > $g1; +$v = $m1 <= $g1; +$v = $m1 >= $g1; +$v = $m1 == $g1; +$v = $m1 != $g1; +$v = $m1 <=> $g1; +$v = -$m1; +EXPECT +Use of uninitialized value $g1 in integer addition (+) at - line 6. +Use of uninitialized value $m1 in integer addition (+) at - line 6. +Use of uninitialized value $g1 in integer subtraction (-) at - line 7. +Use of uninitialized value $m1 in integer subtraction (-) at - line 7. +Use of uninitialized value $g1 in integer multiplication (*) at - line 8. +Use of uninitialized value $m1 in integer multiplication (*) at - line 8. +Use of uninitialized value $g1 in integer division (/) at - line 9. +Use of uninitialized value $m2 in integer division (/) at - line 10. +Use of uninitialized value $g1 in integer modulus (%) at - line 11. +Use of uninitialized value $m1 in integer modulus (%) at - line 11. +Use of uninitialized value $m2 in integer modulus (%) at - line 12. +Use of uninitialized value $g1 in integer lt (<) at - line 13. +Use of uninitialized value $m1 in integer lt (<) at - line 13. +Use of uninitialized value $g1 in integer gt (>) at - line 14. +Use of uninitialized value $m1 in integer gt (>) at - line 14. +Use of uninitialized value $g1 in integer le (<=) at - line 15. +Use of uninitialized value $m1 in integer le (<=) at - line 15. +Use of uninitialized value $g1 in integer ge (>=) at - line 16. +Use of uninitialized value $m1 in integer ge (>=) at - line 16. +Use of uninitialized value $g1 in integer eq (==) at - line 17. +Use of uninitialized value $m1 in integer eq (==) at - line 17. +Use of uninitialized value $g1 in integer ne (!=) at - line 18. +Use of uninitialized value $m1 in integer ne (!=) at - line 18. +Use of uninitialized value $g1 in integer comparison (<=>) at - line 19. +Use of uninitialized value $m1 in integer comparison (<=>) at - line 19. +Use of uninitialized value $m1 in integer negation (-) at - line 20. +######## +use warnings 'uninitialized'; +my ($m1, $m2, $v); +our ($g1, $g2); + +$v = int($g1); +$v = abs($g2); +EXPECT +Use of uninitialized value $g1 in int at - line 5. +Use of uninitialized value $g1 in int at - line 5. +Use of uninitialized value $g2 in abs at - line 6. +Use of uninitialized value $g2 in abs at - line 6. +######## +use warnings 'uninitialized'; +my ($m1, $m2, $v); +our ($g1); + +$v = pack $m1; +$v = pack "i*", $m2, $g1, $g2; +my @unpack = unpack $m1, $m2; +EXPECT +Use of uninitialized value $m1 in pack at - line 5. +Use of uninitialized value $m2 in pack at - line 6. +Use of uninitialized value $g1 in pack at - line 6. +Use of uninitialized value $g2 in pack at - line 6. +Use of uninitialized value $m1 in unpack at - line 7. +Use of uninitialized value $m2 in unpack at - line 7. +######## +use warnings 'uninitialized'; +my ($m1); +our ($g1); + +my @sort; +@sort = sort $m1, $g1; +@sort = sort {$a <=> $b} $m1, $g1; +sub sortf {$a-1 <=> $b-1}; +@sort = sort &sortf, $m1, $g1; +EXPECT +Use of uninitialized value $m1 in sort at - line 6. +Use of uninitialized value $g1 in sort at - line 6. +Use of uninitialized value $m1 in sort at - line 6. +Use of uninitialized value $g1 in sort at - line 6. +Use of uninitialized value $m1 in sort at - line 7. +Use of uninitialized value $g1 in sort at - line 7. +Use of uninitialized value $m1 in sort at - line 7. +Use of uninitialized value $g1 in sort at - line 7. +Use of uninitialized value $a in subtraction (-) at - line 8. +Use of uninitialized value $b in subtraction (-) at - line 8. +Use of uninitialized value $m1 in sort at - line 9. +Use of uninitialized value $g1 in sort at - line 9. +Use of uninitialized value $m1 in sort at - line 9. +Use of uninitialized value $m1 in sort at - line 9. +Use of uninitialized value $g1 in sort at - line 9. +Use of uninitialized value $g1 in sort at - line 9. +######## +use warnings 'uninitialized'; +my ($m1, $m2, $v); +our ($g1); + +eval { $v = $m1 / $g1 }; +$v = $m2 / 2; +eval { $v = $m1 % $g1 }; +$v = $m2 % 2; +$v = $m1 == $g1; +$v = $m1 >= $g1; +$v = $m1 > $g1; +$v = $m1 <= $g1; +$v = $m1 < $g1; +$v = $m1 * $g1; +$v = $m1 <=>$g1; +$v = $m1 != $g1; +$v = $m1 -$g1; +$v = $m1 ** $g1; +$v = $m1 + $g1; +$v = $m1 - $g1; +EXPECT +Use of uninitialized value $g1 in division (/) at - line 5. +Use of uninitialized value $m1 in division (/) at - line 5. +Use of uninitialized value $m2 in division (/) at - line 6. +Use of uninitialized value $g1 in modulus (%) at - line 7. +Use of uninitialized value $m1 in modulus (%) at - line 7. +Use of uninitialized value $m2 in modulus (%) at - line 8. +Use of uninitialized value $g1 in numeric eq (==) at - line 9. +Use of uninitialized value $m1 in numeric eq (==) at - line 9. +Use of uninitialized value $g1 in numeric ge (>=) at - line 10. +Use of uninitialized value $m1 in numeric ge (>=) at - line 10. +Use of uninitialized value $g1 in numeric gt (>) at - line 11. +Use of uninitialized value $m1 in numeric gt (>) at - line 11. +Use of uninitialized value $g1 in numeric le (<=) at - line 12. +Use of uninitialized value $m1 in numeric le (<=) at - line 12. +Use of uninitialized value $g1 in numeric lt (<) at - line 13. +Use of uninitialized value $m1 in numeric lt (<) at - line 13. +Use of uninitialized value $g1 in multiplication (*) at - line 14. +Use of uninitialized value $m1 in multiplication (*) at - line 14. +Use of uninitialized value $g1 in numeric comparison (<=>) at - line 15. +Use of uninitialized value $m1 in numeric comparison (<=>) at - line 15. +Use of uninitialized value $g1 in numeric ne (!=) at - line 16. +Use of uninitialized value $m1 in numeric ne (!=) at - line 16. +Use of uninitialized value $g1 in subtraction (-) at - line 17. +Use of uninitialized value $m1 in subtraction (-) at - line 17. +Use of uninitialized value $g1 in exponentiation (**) at - line 18. +Use of uninitialized value $m1 in exponentiation (**) at - line 18. +Use of uninitialized value $g1 in addition (+) at - line 19. +Use of uninitialized value $m1 in addition (+) at - line 19. +Use of uninitialized value $g1 in subtraction (-) at - line 20. +Use of uninitialized value $m1 in subtraction (-) at - line 20. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +$v = *global1{$m1}; +$v = prototype $g1; +$v = bless [], $g1; +$v = `$m1`; + +$v = $m1 . $g1; +EXPECT +Use of uninitialized value $m1 in glob elem at - line 5. +Use of uninitialized value $g1 in subroutine prototype at - line 6. +Use of uninitialized value $g1 in bless at - line 7. +Use of uninitialized value $m1 in quoted execution (``, qx) at - line 8. +Use of uninitialized value $g1 in concatenation (.) or string at - line 10. +Use of uninitialized value $m1 in concatenation (.) or string at - line 10. +######## +use warnings 'uninitialized'; +my ($m1); +our ($g1, $g2); + +/y/; +/$m1/; +/$g1/; + +s/y/z/; undef $_; +s/$m1/z/; undef $_; +s//$g1/; undef $_; +s/$m1/$g1/; undef $_; +tr/x/y/; undef $_; + +my $_; +/y/; +/$m1/; +/$g1/; +s/y/z/; undef $_; +s/$m1/z/; undef $_; +s//$g1/; undef $_; +s/$m1/$g1/; undef $_; +tr/x/y/; undef $_; + +$g2 =~ /y/; +$g2 =~ /$m1/; +$g2 =~ /$g1/; +$g2 =~ s/y/z/; undef $g2; +$g2 =~ s/$m1/z/; undef $g2; +$g2 =~ s//$g1/; undef $g2; +$g2 =~ s/$m1/$g1/; undef $g2; +$g2 =~ tr/x/y/; undef $g2; # XXX can't extract var name yet + +my $foo = "abc"; +$foo =~ /$m1/; +$foo =~ /$g1/; +$foo =~ s/y/z/; +$foo =~ s/$m1/z/; +$foo =~ s//$g1/; +$foo =~ s/$m1/$g1/; +$foo =~ s/./$m1/e; +EXPECT +Use of uninitialized value $_ in pattern match (m//) at - line 5. +Use of uninitialized value $m1 in regexp compilation at - line 6. +Use of uninitialized value $_ in pattern match (m//) at - line 6. +Use of uninitialized value $g1 in regexp compilation at - line 7. +Use of uninitialized value $_ in pattern match (m//) at - line 7. +Use of uninitialized value $_ in substitution (s///) at - line 9. +Use of uninitialized value $m1 in regexp compilation at - line 10. +Use of uninitialized value $_ in substitution (s///) at - line 10. +Use of uninitialized value $_ in substitution (s///) at - line 10. +Use of uninitialized value $_ in substitution (s///) at - line 11. +Use of uninitialized value $g1 in substitution (s///) at - line 11. +Use of uninitialized value $_ in substitution (s///) at - line 11. +Use of uninitialized value $g1 in substitution (s///) at - line 11. +Use of uninitialized value $m1 in regexp compilation at - line 12. +Use of uninitialized value $_ in substitution (s///) at - line 12. +Use of uninitialized value $_ in substitution (s///) at - line 12. +Use of uninitialized value $g1 in substitution iterator at - line 12. +Use of uninitialized value $_ in transliteration (tr///) at - line 13. +Use of uninitialized value $_ in pattern match (m//) at - line 16. +Use of uninitialized value $m1 in regexp compilation at - line 17. +Use of uninitialized value $_ in pattern match (m//) at - line 17. +Use of uninitialized value $g1 in regexp compilation at - line 18. +Use of uninitialized value $_ in pattern match (m//) at - line 18. +Use of uninitialized value $_ in substitution (s///) at - line 19. +Use of uninitialized value $m1 in regexp compilation at - line 20. +Use of uninitialized value $_ in substitution (s///) at - line 20. +Use of uninitialized value $_ in substitution (s///) at - line 20. +Use of uninitialized value $_ in substitution (s///) at - line 21. +Use of uninitialized value $g1 in substitution (s///) at - line 21. +Use of uninitialized value $_ in substitution (s///) at - line 21. +Use of uninitialized value $g1 in substitution (s///) at - line 21. +Use of uninitialized value $m1 in regexp compilation at - line 22. +Use of uninitialized value $_ in substitution (s///) at - line 22. +Use of uninitialized value $_ in substitution (s///) at - line 22. +Use of uninitialized value $g1 in substitution iterator at - line 22. +Use of uninitialized value $_ in transliteration (tr///) at - line 23. +Use of uninitialized value $g2 in pattern match (m//) at - line 25. +Use of uninitialized value $m1 in regexp compilation at - line 26. +Use of uninitialized value $g2 in pattern match (m//) at - line 26. +Use of uninitialized value $g1 in regexp compilation at - line 27. +Use of uninitialized value $g2 in pattern match (m//) at - line 27. +Use of uninitialized value $g2 in substitution (s///) at - line 28. +Use of uninitialized value $m1 in regexp compilation at - line 29. +Use of uninitialized value $g2 in substitution (s///) at - line 29. +Use of uninitialized value $g2 in substitution (s///) at - line 29. +Use of uninitialized value $g2 in substitution (s///) at - line 30. +Use of uninitialized value $g1 in substitution (s///) at - line 30. +Use of uninitialized value $g2 in substitution (s///) at - line 30. +Use of uninitialized value $g1 in substitution (s///) at - line 30. +Use of uninitialized value $m1 in regexp compilation at - line 31. +Use of uninitialized value $g2 in substitution (s///) at - line 31. +Use of uninitialized value $g2 in substitution (s///) at - line 31. +Use of uninitialized value $g1 in substitution iterator at - line 31. +Use of uninitialized value in transliteration (tr///) at - line 32. +Use of uninitialized value $m1 in regexp compilation at - line 35. +Use of uninitialized value $g1 in regexp compilation at - line 36. +Use of uninitialized value $m1 in regexp compilation at - line 38. +Use of uninitialized value $g1 in substitution (s///) at - line 39. +Use of uninitialized value $m1 in regexp compilation at - line 40. +Use of uninitialized value $g1 in substitution iterator at - line 40. +Use of uninitialized value $m1 in substitution iterator at - line 41. +######## +use warnings 'uninitialized'; +my ($m1); + +{ my $foo = "abc"; (substr($foo,0,0)) = ($m1) } +EXPECT +Use of uninitialized value $m1 in list assignment at - line 4. +######## +use warnings 'uninitialized'; +our ($g1); + +study; +study $g1; +EXPECT +Use of uninitialized value $_ in study at - line 4. +Use of uninitialized value $g1 in study at - line 5. +######## +use warnings 'uninitialized'; +my ($m1); + +pos()=0; +pos($m1)=0; +EXPECT +Use of uninitialized value $_ in scalar assignment at - line 4. +Use of uninitialized value $m1 in scalar assignment at - line 5. +######## +use warnings 'uninitialized'; +my ($m1); + +{ my $x = "a" x $m1 } # NB LHS of repeat does not warn +{ my @x = ("a") x $m1 } +EXPECT +Use of uninitialized value $m1 in repeat (x) at - line 4. +Use of uninitialized value $m1 in repeat (x) at - line 5. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +$v = "$m1"; + +$v = $m1 lt $g1; +$v = $m1 le $g1; +$v = $m1 gt $g1; +$v = $m1 ge $g1; +$v = $m1 eq $g1; +$v = $m1 ne $g1; +$v = $m1 cmp $g1; +EXPECT +Use of uninitialized value $m1 in string at - line 5. +Use of uninitialized value $m1 in string lt at - line 7. +Use of uninitialized value $g1 in string lt at - line 7. +Use of uninitialized value $m1 in string le at - line 8. +Use of uninitialized value $g1 in string le at - line 8. +Use of uninitialized value $m1 in string gt at - line 9. +Use of uninitialized value $g1 in string gt at - line 9. +Use of uninitialized value $m1 in string ge at - line 10. +Use of uninitialized value $g1 in string ge at - line 10. +Use of uninitialized value $m1 in string eq at - line 11. +Use of uninitialized value $g1 in string eq at - line 11. +Use of uninitialized value $m1 in string ne at - line 12. +Use of uninitialized value $g1 in string ne at - line 12. +Use of uninitialized value $m1 in string comparison (cmp) at - line 13. +Use of uninitialized value $g1 in string comparison (cmp) at - line 13. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +$v = atan2($m1,$g1); +$v = sin $m1; +$v = cos $m1; +$v = rand $m1; +$v = srand $m1; +$v = exp $m1; +$v = eval {log $m1}; +$v = sqrt $m1; +$v = hex $m1; +$v = oct $m1; +$v = length $m1; +$v = length; +EXPECT +Use of uninitialized value $g1 in atan2 at - line 5. +Use of uninitialized value $m1 in atan2 at - line 5. +Use of uninitialized value $m1 in sin at - line 6. +Use of uninitialized value $m1 in cos at - line 7. +Use of uninitialized value $m1 in rand at - line 8. +Use of uninitialized value $m1 in srand at - line 9. +Use of uninitialized value $m1 in exp at - line 10. +Use of uninitialized value $m1 in log at - line 11. +Use of uninitialized value $m1 in sqrt at - line 12. +Use of uninitialized value $m1 in hex at - line 13. +Use of uninitialized value $m1 in oct at - line 14. +Use of uninitialized value $m1 in length at - line 15. +Use of uninitialized value $_ in length at - line 16. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +$v = substr $m1, $g1; +$v = substr $m1, $g1, $m2; +$v = substr $m1, $g1, $m2, $g2; undef $m1; +substr($m1, $g1) = $g2; undef $m1; # NB global2 +substr($m1, $g1, $m2) = $g2; undef $m1; # isn't identified + +$v = eval {vec ($m1, $g1, $m2)}; +eval {vec ($m1, $g1, $m2) = $g2}; undef $m1; # ditto + +$v = index $m1, $m2; +$v = index $m1, $m2, $g1; +$v = rindex $m1, $m2; +$v = rindex $m1, $m2, $g1; +EXPECT +Use of uninitialized value $g1 in substr at - line 5. +Use of uninitialized value $m1 in substr at - line 5. +Use of uninitialized value $m2 in substr at - line 6. +Use of uninitialized value $g1 in substr at - line 6. +Use of uninitialized value $m1 in substr at - line 6. +Use of uninitialized value $g2 in substr at - line 7. +Use of uninitialized value $m2 in substr at - line 7. +Use of uninitialized value $g1 in substr at - line 7. +Use of uninitialized value $m1 in substr at - line 7. +Use of uninitialized value $m1 in substr at - line 7. +Use of uninitialized value $g1 in substr at - line 8. +Use of uninitialized value $m1 in substr at - line 8. +Use of uninitialized value in scalar assignment at - line 8. +Use of uninitialized value $m2 in substr at - line 9. +Use of uninitialized value $g1 in substr at - line 9. +Use of uninitialized value $m1 in substr at - line 9. +Use of uninitialized value in scalar assignment at - line 9. +Use of uninitialized value $m2 in vec at - line 11. +Use of uninitialized value $g1 in vec at - line 11. +Use of uninitialized value $m1 in vec at - line 11. +Use of uninitialized value $m2 in vec at - line 12. +Use of uninitialized value $g1 in vec at - line 12. +Use of uninitialized value $m1 in vec at - line 12. +Use of uninitialized value $m1 in index at - line 14. +Use of uninitialized value $m2 in index at - line 14. +Use of uninitialized value $g1 in index at - line 15. +Use of uninitialized value $m1 in index at - line 15. +Use of uninitialized value $m2 in index at - line 15. +Use of uninitialized value $m2 in rindex at - line 16. +Use of uninitialized value $m1 in rindex at - line 16. +Use of uninitialized value $g1 in rindex at - line 17. +Use of uninitialized value $m2 in rindex at - line 17. +Use of uninitialized value $m1 in rindex at - line 17. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +$v = sprintf $m1; +$v = sprintf '%d%d%d%d', $m1, $m2, $g1, $g2; +eval {formline $m1 }; undef $m1; +formline '@<<@<<@<<@<<', $m1, $m2, $g1, $g2; +EXPECT +Use of uninitialized value $m1 in sprintf at - line 5. +Use of uninitialized value $m1 in sprintf at - line 6. +Use of uninitialized value $m2 in sprintf at - line 6. +Use of uninitialized value $g1 in sprintf at - line 6. +Use of uninitialized value $g2 in sprintf at - line 6. +Use of uninitialized value $m1 in formline at - line 7. +Use of uninitialized value $m1 in formline at - line 8. +Use of uninitialized value $m2 in formline at - line 8. +Use of uninitialized value $g1 in formline at - line 8. +Use of uninitialized value $g2 in formline at - line 8. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +$v = crypt $m1, $g1; + +$v = ord; +$v = ord $m1; +$v = chr; +$v = chr $m1; + +# XXX these functions don't warn! +$v = ucfirst; +$v = ucfirst $m1; +$v = lcfirst; +$v = lcfirst $m1; +$v = uc; +$v = uc $m1; +$v = lc; +$v = lc $m1; + +$v = quotemeta; +$v = quotemeta $m1; +EXPECT +Use of uninitialized value $m1 in crypt at - line 5. +Use of uninitialized value $g1 in crypt at - line 5. +Use of uninitialized value $_ in ord at - line 7. +Use of uninitialized value $m1 in ord at - line 8. +Use of uninitialized value $_ in chr at - line 9. +Use of uninitialized value $m1 in chr at - line 10. +Use of uninitialized value $_ in quotemeta at - line 22. +Use of uninitialized value $m1 in quotemeta at - line 23. +######## +use warnings 'uninitialized'; +my ($m1, $v1, $v2, $v3, $v4); +our ($g1); + +($v1,$v2,$v3,$v4) = split; +($v1,$v2,$v3,$v4) = split $m1; +($v1,$v2,$v3,$v4) = split $m1, $m2; +($v1,$v2,$v3,$v4) = split $m1, $m2, $g1; + +$v1 = join $m1; +$v2 = join $m1, $m2; +$v3 = join $m1, $m2, $m3; +EXPECT +Use of uninitialized value $_ in split at - line 5. +Use of uninitialized value $m1 in regexp compilation at - line 6. +Use of uninitialized value $_ in split at - line 6. +Use of uninitialized value $m1 in regexp compilation at - line 7. +Use of uninitialized value $m2 in split at - line 7. +Use of uninitialized value $m1 in regexp compilation at - line 8. +Use of uninitialized value $g1 in split at - line 8. +Use of uninitialized value $m2 in split at - line 8. +Use of uninitialized value $m1 in join or string at - line 10. +Use of uninitialized value $m1 in join or string at - line 11. +Use of uninitialized value $m2 in join or string at - line 11. +Use of uninitialized value $m1 in join or string at - line 12. +Use of uninitialized value $m2 in join or string at - line 12. +Use of uninitialized value $m3 in join or string at - line 12. +######## +use warnings 'uninitialized'; +my ($m1, $m2, @ma, $v); + +our @foo1=(1,undef); chomp @foo1; +my @foo2=(1,undef); chomp @foo2; +our @foo3=(1,undef); chop @foo3; +my @foo4=(1,undef); chop @foo4; +our @foo5=(1,undef); $v = sprintf "%s%s",@foo5; +my @foo6=(1,undef); $v = sprintf "%s%s",@foo6; +our %foo7=('foo'=>'bar','baz'=>undef); $v = sprintf "%s%s",%foo7; +my %foo8=('foo'=>'bar','baz'=>undef); $v = sprintf "%s%s",%foo8; +our @foo9 =(1,undef); $v = sprintf "%s%s%s%s",$m1,@foo9, $ma[2]; +my @foo10=(1,undef); $v = sprintf "%s%s%s%s",$m2,@foo10,$ma[2]; +our %foo11=('foo'=>'bar','baz'=>undef); $v = join '', %foo11; +my %foo12=('foo'=>'bar','baz'=>undef); $v = join '', %foo12; +our %foo13=(1..2000,'foo'=>'bar','baz'=>undef); $v = join '', %foo13; +my %foo14=(1..2000,'foo'=>'bar','baz'=>undef); $v = join '', %foo14; +EXPECT +Use of uninitialized value $foo1[1] in chomp at - line 4. +Use of uninitialized value $foo2[1] in chomp at - line 5. +Use of uninitialized value $foo3[1] in chop at - line 6. +Use of uninitialized value $foo4[1] in chop at - line 7. +Use of uninitialized value $foo5[1] in sprintf at - line 8. +Use of uninitialized value $foo6[1] in sprintf at - line 9. +Use of uninitialized value $foo7{"baz"} in sprintf at - line 10. +Use of uninitialized value $foo8{"baz"} in sprintf at - line 11. +Use of uninitialized value $m1 in sprintf at - line 12. +Use of uninitialized value $foo9[1] in sprintf at - line 12. +Use of uninitialized value in sprintf at - line 12. +Use of uninitialized value $m2 in sprintf at - line 13. +Use of uninitialized value $foo10[1] in sprintf at - line 13. +Use of uninitialized value in sprintf at - line 13. +Use of uninitialized value $foo11{"baz"} in join or string at - line 14. +Use of uninitialized value $foo12{"baz"} in join or string at - line 15. +Use of uninitialized value within %foo13 in join or string at - line 16. +Use of uninitialized value within %foo14 in join or string at - line 17. +######## +use warnings 'uninitialized'; +my ($v); + +undef $^A; $v = $^A + ${^FOO}; # should output '^A' not chr(1) +*GLOB1 = *GLOB2; +$v = $GLOB1 + 1; +$v = $GLOB2 + 1; +EXPECT +Use of uninitialized value $^FOO in addition (+) at - line 4. +Use of uninitialized value $^A in addition (+) at - line 4. +Use of uninitialized value $GLOB1 in addition (+) at - line 6. +Use of uninitialized value $GLOB2 in addition (+) at - line 7. +######## +use warnings 'uninitialized'; +my ($v); + +# check hash key is sanitised +my %h = ("\0011\002\r\n\t\f\"\\abcdefghijklmnopqrstuvwxyz", undef); +$v = join '', %h; +EXPECT +Use of uninitialized value $h{"\0011\2\r\n\t\f\"\\abcdefghijkl"...} in join or string at - line 6. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +$v = eval { \&$m1 }; +$v = eval { \&$g1 }; + +my @a; +@a = splice @a, $m1, $g1; +$v = 1 + splice @a, $m1, $g1; + +my $x = bless [], 'Z'; +eval { $x->$m1() }; + +eval { &$m1() }; +eval { &$g1() }; + +warn $m1,$g1,"foo"; + +eval { die $m1, $g1 }; + +reset $m1; +reset $g1; +EXPECT +Use of uninitialized value $m1 in subroutine dereference at - line 5. +Use of uninitialized value $m1 in subroutine dereference at - line 5. +Use of uninitialized value $g1 in subroutine dereference at - line 6. +Use of uninitialized value $g1 in subroutine dereference at - line 6. +Use of uninitialized value $m1 in splice at - line 9. +Use of uninitialized value $g1 in splice at - line 9. +Use of uninitialized value $m1 in splice at - line 10. +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 $m1 in subroutine entry at - line 15. +Use of uninitialized value $g1 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. +Use of uninitialized value $m1 in die at - line 20. +Use of uninitialized value $g1 in die at - line 20. +Use of uninitialized value $m1 in symbol reset at - line 22. +Use of uninitialized value $g1 in symbol reset at - line 23. +######## +use warnings 'uninitialized'; +my ($m1); +our ($g1); + +open FOO; # accesses $FOO +my $foo = 'FO'; +open($foo."O"); # accesses $FOO +open my $x; # accesses ${*$x} +open $foobar; # accesses ${*$foobar} +my $y; +open $y, $m1; +eval { open $y, $m1, $g1 }; +open $y, '<', $g1; + +sysopen $y, $m1, $m2; +sysopen $y, $m1, $g1, $m2; + +my $old = umask; +umask $m1; +umask $g1; +umask $old; + +binmode STDIN, $m1; +EXPECT +Use of uninitialized value $FOO in open at - line 5. +Use of uninitialized value in open at - line 7. +Use of uninitialized value in open at - line 8. +Use of uninitialized value in open at - line 9. +Use of uninitialized value $m1 in open at - line 11. +Use of uninitialized value $m1 in open at - line 12. +Use of uninitialized value $g1 in open at - line 13. +Use of uninitialized value $m2 in sysopen at - line 15. +Use of uninitialized value $m1 in sysopen at - line 15. +Use of uninitialized value $m2 in sysopen at - line 16. +Use of uninitialized value $g1 in sysopen at - line 16. +Use of uninitialized value $m1 in sysopen at - line 16. +Use of uninitialized value $m1 in umask at - line 19. +Use of uninitialized value $g1 in umask at - line 20. +Use of uninitialized value $m1 in binmode at - line 23. +Use of uninitialized value $m1 in binmode at - line 23. +######## +use warnings 'uninitialized'; +my ($m1); +our ($g1); + +eval { my $x; tie $x, $m1 }; + +eval { my $x; read $m1, $x, $g1 }; +eval { my $x; read $m1, $x, $g1, $g2 }; +eval { my $x; sysread $m1, $x, $g1 }; +eval { my $x; sysread $m1, $x, $g1, $g2 }; +EXPECT +Use of uninitialized value $m1 in tie at - line 5. +Use of uninitialized value $m1 in tie at - line 5. +Use of uninitialized value $m1 in ref-to-glob cast at - line 7. +Use of uninitialized value $g1 in read at - line 7. +Use of uninitialized value $m1 in ref-to-glob cast at - line 8. +Use of uninitialized value $g1 in read at - line 8. +Use of uninitialized value $g2 in read at - line 8. +Use of uninitialized value $m1 in ref-to-glob cast at - line 9. +Use of uninitialized value $g1 in sysread at - line 9. +Use of uninitialized value $m1 in ref-to-glob cast at - line 10. +Use of uninitialized value $g1 in sysread at - line 10. +Use of uninitialized value $g2 in sysread at - line 10. +######## +use warnings 'uninitialized'; +my ($m1); +our ($g1, @ga); + +printf $m1; +printf STDERR "%d%d%d%d\n", $m1, $m2, $g1, $g2; +printf $ga[1000]; +printf STDERR "FOO1:%s\n", $ga[1000]; +printf STDERR "FOO2:%s%s%s%s\n", $m1, $g1, $ga[1],$m2; +printf STDERR "FOO3:%s%s%s\n", "X", $ga[1],"Y"; +EXPECT +Use of uninitialized value $m1 in printf at - line 5. +Use of uninitialized value $m1 in printf at - line 6. +Use of uninitialized value $m2 in printf at - line 6. +Use of uninitialized value $g1 in printf at - line 6. +Use of uninitialized value $g2 in printf at - line 6. +0000 +Use of uninitialized value $ga[1000] in printf at - line 7. +Use of uninitialized value $ga[1000] in printf at - line 8. +FOO1: +Use of uninitialized value $m1 in printf at - line 9. +Use of uninitialized value $g1 in printf at - line 9. +Use of uninitialized value in printf at - line 9. +Use of uninitialized value $m2 in printf at - line 9. +FOO2: +Use of uninitialized value $ga[1] in printf at - line 10. +FOO3:XY +######## +use warnings 'uninitialized'; +my ($m1); +our ($g1); + +eval { my $x; seek $x,$m1, $g1 }; +eval { my $x; sysseek $x,$m1, $g1 }; +eval { syswrite $m1, $g1 }; +eval { syswrite STDERR, $m1 }; +eval { syswrite STDERR, $m1, $g1 }; +eval { syswrite STDERR, $m1, $g1, $m2 }; +eval { my $x; flock $x, $g1 }; +eval { my $x; socket $x, $m1, $g1, $m2 }; +eval { my ($x,$y); socketpair $x, $y, $m1, $g1, $m2 }; +EXPECT +Use of uninitialized value $x in ref-to-glob cast at - line 5. +Use of uninitialized value $g1 in seek at - line 5. +Use of uninitialized value $m1 in seek at - line 5. +Use of uninitialized value $x in ref-to-glob cast at - line 6. +Use of uninitialized value $g1 in sysseek at - line 6. +Use of uninitialized value $m1 in sysseek at - line 6. +Use of uninitialized value $m1 in ref-to-glob cast at - line 7. +Use of uninitialized value $g1 in syswrite at - line 7. +Use of uninitialized value $m1 in syswrite at - line 8. +Use of uninitialized value $m1 in syswrite at - line 8. +Use of uninitialized value $g1 in syswrite at - line 9. +Use of uninitialized value $m1 in syswrite at - line 9. +Use of uninitialized value $g1 in syswrite at - line 10. +Use of uninitialized value $m1 in syswrite at - line 10. +Use of uninitialized value $m2 in syswrite at - line 10. +Use of uninitialized value $x in ref-to-glob cast at - line 11. +Use of uninitialized value $g1 in flock at - line 11. +Use of uninitialized value $m2 in socket at - line 12. +Use of uninitialized value $g1 in socket at - line 12. +Use of uninitialized value $m1 in socket at - line 12. +Use of uninitialized value $m2 in socketpair at - line 13. +Use of uninitialized value $g1 in socketpair at - line 13. +Use of uninitialized value $m1 in socketpair at - line 13. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +stat; +lstat; +stat $m1; +lstat $g1; + +$v = -R $m1; +$v = -W $m1; +$v = -X $m1; +$v = -r $m1; +$v = -w $m1; +$v = -x $m1; +$v = -e $m1; +$v = -O $m1; +$v = -o $m1; +$v = -z $m1; +$v = -s $m1; +$v = -M $m1; +$v = -A $m1; +$v = -C $m1; +$v = -S $m1; +$v = -c $m1; +$v = -b $m1; +$v = -f $m1; +$v = -d $m1; +$v = -p $m1; +$v = -l $m1; +$v = -u $m1; +$v = -g $m1; +$v = -k $m1; +$v = -t $m1; +$v = -T $m1; +$v = -B $m1; +EXPECT +Use of uninitialized value $_ in stat at - line 5. +Use of uninitialized value $_ in lstat at - line 6. +Use of uninitialized value $m1 in stat at - line 7. +Use of uninitialized value $g1 in lstat at - line 8. +Use of uninitialized value $m1 in -R at - line 10. +Use of uninitialized value $m1 in -W at - line 11. +Use of uninitialized value $m1 in -X at - line 12. +Use of uninitialized value $m1 in -r at - line 13. +Use of uninitialized value $m1 in -w at - line 14. +Use of uninitialized value $m1 in -x at - line 15. +Use of uninitialized value $m1 in -e at - line 16. +Use of uninitialized value $m1 in -o at - line 17. +Use of uninitialized value $m1 in -O at - line 18. +Use of uninitialized value $m1 in -z at - line 19. +Use of uninitialized value $m1 in -s at - line 20. +Use of uninitialized value $m1 in -M at - line 21. +Use of uninitialized value $m1 in -A at - line 22. +Use of uninitialized value $m1 in -C at - line 23. +Use of uninitialized value $m1 in -S at - line 24. +Use of uninitialized value $m1 in -c at - line 25. +Use of uninitialized value $m1 in -b at - line 26. +Use of uninitialized value $m1 in -f at - line 27. +Use of uninitialized value $m1 in -d at - line 28. +Use of uninitialized value $m1 in -p at - line 29. +Use of uninitialized value $m1 in -l at - line 30. +Use of uninitialized value $m1 in -l at - line 30. +Use of uninitialized value $m1 in -u at - line 31. +Use of uninitialized value $m1 in -g at - line 32. +Use of uninitialized value $m1 in -k at - line 33. +Use of uninitialized value $m1 in -t at - line 34. +Use of uninitialized value $m1 in -T at - line 35. +Use of uninitialized value $m1 in -B at - line 36. +######## +use warnings 'uninitialized'; +my ($m1, $v); +our ($g1); + +$v = localtime $m1; +$v = gmtime $g1; +EXPECT +Use of uninitialized value $m1 in localtime at - line 5. +Use of uninitialized value $g1 in gmtime at - line 6. +######## +use warnings 'uninitialized'; +my ($m1, $v); + +$v = eval; +$v = eval $m1; +EXPECT +Use of uninitialized value $_ in eval "string" at - line 4. +Use of uninitialized value $_ in eval "string" at - line 4. +Use of uninitialized value $_ in eval "string" at - line 4. +Use of uninitialized value $m1 in eval "string" at - line 5. +Use of uninitialized value $m1 in eval "string" at - line 5. +Use of uninitialized value $m1 in eval "string" at - line 5. +######## +use warnings 'uninitialized'; +my ($m1); + +exit $m1; +EXPECT +Use of uninitialized value $m1 in exit at - line 4. diff --git a/t/lib/warnings/doio b/t/lib/warnings/doio index 15d4c5e..a451846 100644 --- a/t/lib/warnings/doio +++ b/t/lib/warnings/doio @@ -143,7 +143,7 @@ print $a ; no warnings 'uninitialized' ; print $b ; EXPECT -Use of uninitialized value in print at - line 3. +Use of uninitialized value $a in print at - line 3. ######## # doio.c [Perl_my_stat Perl_my_lstat] use warnings 'io' ; diff --git a/t/lib/warnings/mg b/t/lib/warnings/mg index f7c3ebf..c6d7506 100644 --- a/t/lib/warnings/mg +++ b/t/lib/warnings/mg @@ -48,10 +48,10 @@ use warnings 'uninitialized'; 'foo' =~ /(foo)/; length $3; EXPECT -Use of uninitialized value in length at - line 4. +Use of uninitialized value $3 in length at - line 4. ######## # mg.c use warnings 'uninitialized'; length $3; EXPECT -Use of uninitialized value in length at - line 3. +Use of uninitialized value $3 in length at - line 3. diff --git a/t/lib/warnings/pp b/t/lib/warnings/pp index 5ed7aa0..d158144 100644 --- a/t/lib/warnings/pp +++ b/t/lib/warnings/pp @@ -59,7 +59,7 @@ $x = undef; $y = $$x; no warnings 'uninitialized' ; $u = undef; $v = $$u; EXPECT -Use of uninitialized value in scalar dereference at - line 3. +Use of uninitialized value $x in scalar dereference at - line 3. ######## # pp.c use warnings 'misc' ; diff --git a/t/lib/warnings/pp_ctl b/t/lib/warnings/pp_ctl index 59ced2b..d27e896 100644 --- a/t/lib/warnings/pp_ctl +++ b/t/lib/warnings/pp_ctl @@ -219,7 +219,7 @@ EXPECT use warnings; eval 'print $foo'; EXPECT -Use of uninitialized value in print at (eval 1) line 1. +Use of uninitialized value $foo in print at (eval 1) line 1. ######## # pp_ctl.c use warnings 'portable'; diff --git a/t/lib/warnings/pp_hot b/t/lib/warnings/pp_hot index 4e10627..f5a5803 100644 --- a/t/lib/warnings/pp_hot +++ b/t/lib/warnings/pp_hot @@ -145,7 +145,7 @@ my @b = @$a; no warnings 'uninitialized' ; my @c = @$a; EXPECT -Use of uninitialized value in array dereference at - line 4. +Use of uninitialized value $a in array dereference at - line 4. ######## # pp_hot.c [pp_rv2hv] use warnings 'uninitialized' ; @@ -154,7 +154,7 @@ my %b = %$a; no warnings 'uninitialized' ; my %c = %$a; EXPECT -Use of uninitialized value in hash dereference at - line 4. +Use of uninitialized value $a in hash dereference at - line 4. ######## # pp_hot.c [pp_aassign] use warnings 'misc' ; @@ -269,11 +269,11 @@ a($x . $y); # should warn twice $x .= $y; # should warn once $y .= $y; # should warn once EXPECT -Use of uninitialized value in concatenation (.) or string at - line 5. -Use of uninitialized value in concatenation (.) or string at - line 6. -Use of uninitialized value in concatenation (.) or string at - line 6. -Use of uninitialized value in concatenation (.) or string at - line 7. -Use of uninitialized value in concatenation (.) or string at - line 8. +Use of uninitialized value $x in concatenation (.) or string at - line 5. +Use of uninitialized value $y in concatenation (.) or string at - line 6. +Use of uninitialized value $x in concatenation (.) or string at - line 6. +Use of uninitialized value $y in concatenation (.) or string at - line 7. +Use of uninitialized value $y in concatenation (.) or string at - line 8. ######## # pp_hot.c [pp_concat] use warnings 'y2k'; diff --git a/t/lib/warnings/pp_pack b/t/lib/warnings/pp_pack index 0f447c7..62ae3a9 100644 --- a/t/lib/warnings/pp_pack +++ b/t/lib/warnings/pp_pack @@ -28,7 +28,7 @@ my $b = $$a; no warnings 'uninitialized' ; my $c = $$a; EXPECT -Use of uninitialized value in scalar dereference at - line 4. +Use of uninitialized value $a in scalar dereference at - line 4. ######## # pp_pack.c use warnings 'pack' ; diff --git a/t/lib/warnings/sv b/t/lib/warnings/sv index b38200d..bf01657 100644 --- a/t/lib/warnings/sv +++ b/t/lib/warnings/sv @@ -58,7 +58,7 @@ $x = 1 + $a[0] ; # a no warnings 'uninitialized' ; $x = 1 + $b[0] ; # a EXPECT -Use of uninitialized value in integer addition (+) at - line 4. +Use of uninitialized value $a[0] in integer addition (+) at - line 4. ######## # sv.c (sv_2iv) package fred ; @@ -73,7 +73,7 @@ $A *= 2 ; no warnings 'uninitialized' ; $A *= 2 ; EXPECT -Use of uninitialized value in integer multiplication (*) at - line 10. +Use of uninitialized value $A in integer multiplication (*) at - line 10. ######## # sv.c use integer ; @@ -82,7 +82,7 @@ my $x *= 2 ; #b no warnings 'uninitialized' ; my $y *= 2 ; #b EXPECT -Use of uninitialized value in integer multiplication (*) at - line 4. +Use of uninitialized value $x in integer multiplication (*) at - line 4. ######## # sv.c (sv_2uv) package fred ; @@ -98,7 +98,7 @@ no warnings 'uninitialized' ; $B = 0 ; $B |= $A ; EXPECT -Use of uninitialized value in bitwise or (|) at - line 10. +Use of uninitialized value $A in bitwise or (|) at - line 10. ######## # sv.c use warnings 'uninitialized' ; @@ -108,7 +108,7 @@ no warnings 'uninitialized' ; my $Y = 1 ; $x = 1 | $b[$Y] ; EXPECT -Use of uninitialized value in bitwise or (|) at - line 4. +Use of uninitialized value within @a in bitwise or (|) at - line 4. ######## # sv.c use warnings 'uninitialized' ; @@ -118,7 +118,7 @@ no warnings 'uninitialized' ; my $Y = 1 ; $x = 1 & $b[$Y] ; EXPECT -Use of uninitialized value in bitwise and (&) at - line 4. +Use of uninitialized value within @a in bitwise and (&) at - line 4. ######## # sv.c use warnings 'uninitialized' ; @@ -128,7 +128,7 @@ no warnings 'uninitialized' ; my $Y = 1 ; $x = ~$b[$Y] ; EXPECT -Use of uninitialized value in 1's complement (~) at - line 4. +Use of uninitialized value within @a in 1's complement (~) at - line 4. ######## # sv.c use warnings 'uninitialized' ; @@ -136,7 +136,7 @@ my $x *= 1 ; # d no warnings 'uninitialized' ; my $y *= 1 ; # d EXPECT -Use of uninitialized value in multiplication (*) at - line 3. +Use of uninitialized value $x in multiplication (*) at - line 3. ######## # sv.c use warnings 'uninitialized' ; @@ -144,7 +144,7 @@ $x = 1 + $a[0] ; # e no warnings 'uninitialized' ; $x = 1 + $b[0] ; # e EXPECT -Use of uninitialized value in addition (+) at - line 3. +Use of uninitialized value $a[0] in addition (+) at - line 3. ######## # sv.c (sv_2nv) package fred ; @@ -158,7 +158,7 @@ $A *= 2 ; no warnings 'uninitialized' ; $A *= 2 ; EXPECT -Use of uninitialized value in multiplication (*) at - line 9. +Use of uninitialized value $A in multiplication (*) at - line 9. ######## # sv.c use warnings 'uninitialized' ; @@ -166,7 +166,7 @@ $x = $y + 1 ; # f no warnings 'uninitialized' ; $x = $z + 1 ; # f EXPECT -Use of uninitialized value in addition (+) at - line 3. +Use of uninitialized value $y in addition (+) at - line 3. ######## # sv.c use warnings 'uninitialized' ; @@ -182,7 +182,7 @@ $x = chop $y ; # h no warnings 'uninitialized' ; $x = chop $z ; # h EXPECT -Use of uninitialized value in scalar chop at - line 3. +Use of uninitialized value $y in scalar chop at - line 3. ######## # sv.c (sv_2pv) package fred ; @@ -198,7 +198,7 @@ no warnings 'uninitialized' ; $C = "" ; $C .= $A ; EXPECT -Use of uninitialized value in concatenation (.) or string at - line 10. +Use of uninitialized value $A in concatenation (.) or string at - line 10. ######## # perlbug 20011116.125 use warnings 'uninitialized'; @@ -207,9 +207,9 @@ $foo = join '', $a, "\n"; $foo = "$a\n"; $foo = "a:$a\n"; EXPECT -Use of uninitialized value in join or string at - line 4. -Use of uninitialized value in concatenation (.) or string at - line 5. -Use of uninitialized value in concatenation (.) or string at - line 6. +Use of uninitialized value $a in join or string at - line 4. +Use of uninitialized value $a in concatenation (.) or string at - line 5. +Use of uninitialized value $a in concatenation (.) or string at - line 6. ######## # sv.c use warnings 'numeric' ; diff --git a/t/lib/warnings/util b/t/lib/warnings/util index 4e960c1..e632d09 100644 --- a/t/lib/warnings/util +++ b/t/lib/warnings/util @@ -115,7 +115,7 @@ if ($x) { } EXPECT Name "main::y" used only once: possible typo at - line 5. -Use of uninitialized value in print at - line 5. +Use of uninitialized value $y in print at - line 5. ######## # util.c use warnings; @@ -126,7 +126,7 @@ if ($x) { } EXPECT Name "main::y" used only once: possible typo at - line 6. -Use of uninitialized value in print at - line 6. +Use of uninitialized value $y in print at - line 6. ######## # util.c use warnings; @@ -140,7 +140,7 @@ if ($x) { } EXPECT Name "main::y" used only once: possible typo at - line 7. -Use of uninitialized value in print at - line 7. +Use of uninitialized value $y in print at - line 7. ######## # util.c use warnings; @@ -155,4 +155,4 @@ if ($x) { } EXPECT Name "main::y" used only once: possible typo at - line 8. -Use of uninitialized value in print at - line 8. +Use of uninitialized value $y in print at - line 8. diff --git a/t/run/fresh_perl.t b/t/run/fresh_perl.t index 0f5073d..d47f27f 100644 --- a/t/run/fresh_perl.t +++ b/t/run/fresh_perl.t @@ -510,7 +510,7 @@ else { if ($x == 0) { print "" } else { print $x } } EXPECT -Use of uninitialized value in numeric eq (==) at - line 4. +Use of uninitialized value $x in numeric eq (==) at - line 4. ######## $x = sub {}; foo(); diff --git a/t/run/runenv.t b/t/run/runenv.t index df4a778..1e36c99 100644 --- a/t/run/runenv.t +++ b/t/run/runenv.t @@ -97,7 +97,7 @@ sub try { try({PERL5OPT => '-w'}, ['-e', 'print $::x'], "", - qq{Name "main::x" used only once: possible typo at -e line 1.\nUse of uninitialized value in print at -e line 1.\n}); + qq{Name "main::x" used only once: possible typo at -e line 1.\nUse of uninitialized value \$x in print at -e line 1.\n}); try({PERL5OPT => '-Mstrict'}, ['-e', 'print $::x'], "", ""); @@ -116,7 +116,7 @@ try({PERL5OPT => '-w -Mstrict'}, ['-e', 'print $::x'], "", < '-w -Mstrict'}, ['-e', 'print $::x'], "", <