From 89474f50ca76e8039d27bebe650de4addd0f1607 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Tue, 1 Nov 2011 18:25:59 -0700 Subject: =?UTF-8?q?Warn=20for=20$[=20=E2=80=98version=E2=80=99=20checks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following Michael Schwern’s suggestion, here is a warning for those hapless folks who use $[ for version checks. It applies whenever $[ is used in one of: < > <= >= --- op.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'op.c') diff --git a/op.c b/op.c index c34dec5f1c..96efde7686 100644 --- a/op.c +++ b/op.c @@ -7284,6 +7284,32 @@ Perl_ck_bitop(pTHX_ OP *o) return o; } +PERL_STATIC_INLINE bool +is_dollar_bracket(pTHX_ const OP * const o) +{ + const OP *kid; + return o->op_type == OP_RV2SV && o->op_flags & OPf_KIDS + && (kid = cUNOPx(o)->op_first) + && kid->op_type == OP_GV + && strEQ(GvNAME(cGVOPx_gv(kid)), "["); +} + +OP * +Perl_ck_cmp(pTHX_ OP *o) +{ + PERL_ARGS_ASSERT_CK_CMP; + if (ckWARN(WARN_SYNTAX)) { + const OP *kid = cUNOPo->op_first; + if (kid && ( + is_dollar_bracket(aTHX_ kid) + || ((kid = kid->op_sibling) && is_dollar_bracket(aTHX_ kid)) + )) + Perl_warner(aTHX_ packWARN(WARN_SYNTAX), + "$[ used in %s (did you mean $] ?)", OP_DESC(o)); + } + return o; +} + OP * Perl_ck_concat(pTHX_ OP *o) { -- cgit v1.2.1