Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strict 'subs' doesn't work about non-existent name used as array index #7173

Closed
p5pRT opened this issue Mar 14, 2004 · 4 comments
Closed

strict 'subs' doesn't work about non-existent name used as array index #7173

p5pRT opened this issue Mar 14, 2004 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 14, 2004

Migrated from rt.perl.org#27628 (status was 'resolved')

Searchable as RT27628$

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2004

From @jlokier

Created by @jlokier

This​:

  perl -e 'use strict; my @​x; $x[FOO] = 1'

gives the following useful error​:

  Bareword "FOO" not allowed while "strict subs" in use at -e line 1.
  Execution of -e aborted due to compilation errors.

So why doesn't this​:

  perl -e 'use strict; our @​x; $x[FOO] = 1'

give an error message? Is this behaviour intentional?

Thanks,
-- Jamie

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.8.0:

Configured by bhcompile'
cf_email='bhcompile at Wed Aug 13 11:45:59 EDT 2003.

Summary of my rderl (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.21-1.1931.2.382.entsmp, archname=i386-linux-thread-multi
    uname='linux str'
    config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef'
 useithreads=define usemultiplicity=
    useperlio= d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=un uselongdouble=
    usemymalloc=, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.2.2 20030222 (Red Hat Linux 3.2.2-5)', gccosandvers=''
gccversion='3.2.2 200302'
    intsize=r, longsize=r, ptrsize=5, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long'
k', ivsize=4'
ivtype='l, nvtype='double'
o_nonbl', nvsize=, Off_t='', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc'
l', ldflags =' -L/u'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libper
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so', d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC'
ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5', lddlflags='s Unicode/Normalize XS/A'

Locally applied patches:
    MAINT18379


@INC for perl v5.8.0:
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    .


Environment for perl v5.8.0:
    HOME=/home/jamie
    LANG=en_GB.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/jamie/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash
    dlflags='-share (unset)

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2004

From @iabyn

On Sun, Mar 14, 2004 at 06​:15​:10AM -0000, Jamie Lokier wrote​:

This​:

perl \-e 'use strict; my @​x; $x\[FOO\] = 1'

gives the following useful error​:

Bareword "FOO" not allowed while "strict subs" in use at \-e line 1\.
Execution of \-e aborted due to compilation errors\.

So why doesn't this​:

perl \-e 'use strict; our @​x; $x\[FOO\] = 1'

give an error message? Is this behaviour intentional?

No, it's a bug! Thanks for the report. It seems to have been introduced
in 5.6.0, and is caused by the peephole optimiser bypassing the bareword
check when looking for a possible constant array index optimisation.

Fixed in the development version of perl by the change below.

Dave.

--
Never do today what you can put off till tomorrow.

Change 22499 by davem@​davem-percy on 2004/03/14 17​:01​:34

  [perl #27628] strict 'subs' didn't warn on bareword array index

Affected files ...

... //depot/perl/op.c#617 edit
... //depot/perl/t/lib/strict/subs#11 edit

Differences ...

==== //depot/perl/op.c#617 (text) ====

@​@​ -6405,7 +6405,7 @​@​
  o->op_next : o->op_next->op_next;
  IV i;
  if (pop && pop->op_type == OP_CONST &&
- (PL_op = pop->op_next) &&
+ ((PL_op = pop->op_next)) &&
  pop->op_next->op_type == OP_AELEM &&
  !(pop->op_next->op_private &
  (OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF|OPpMAYBE_LVSUB)) &&
@​@​ -6414,6 +6414,8 @​@​
  i >= 0)
  {
  GV *gv;
+ if (cSVOPx(pop)->op_private & OPpCONST_STRICT)
+ no_bareword_allowed(pop);
  if (o->op_type == OP_GV)
  op_null(o->op_next);
  op_null(pop->op_next);

==== //depot/perl/t/lib/strict/subs#11 (text) ====

@​@​ -380,3 +380,16 @​@​
EXPECT
Bareword "foo" not allowed while "strict subs" in use at (re_eval 1) line 1.
Compilation failed in regexp at - line 3.
+########
+# [perl #27628] strict 'subs' didn't warn on bareword array index
+use strict 'subs';
+my $x=$a[FOO];
+EXPECT
+Bareword "FOO" not allowed while "strict subs" in use at - line 3.
+Execution of - aborted due to compilation errors.
+########
+use strict 'subs';
+my @​a;my $x=$a[FOO];
+EXPECT
+Bareword "FOO" not allowed while "strict subs" in use at - line 2.
+Execution of - aborted due to compilation errors.

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2004

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2004

@iabyn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant