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

tr///r should warn in void context like s///r, only does in some cases #14680

Open
p5pRT opened this issue Apr 28, 2015 · 1 comment
Open

tr///r should warn in void context like s///r, only does in some cases #14680

p5pRT opened this issue Apr 28, 2015 · 1 comment

Comments

@p5pRT
Copy link

p5pRT commented Apr 28, 2015

Migrated from rt.perl.org#124414 (status was 'new')

Searchable as RT124414$

@p5pRT
Copy link
Author

p5pRT commented Apr 28, 2015

From @avar

Created by @avar

There's been a discrepancy in how s///r and tr///r warn ever since the
warning for tr///r was introduced in v5.13.6-354-gbb16bae.

I discovered a bug in some code today that came down to this logic
error, which doesn't warn​:

  $ /perl5/installed/bin/perl5.21.12 -wE '(my $x = "foo") = tr/f/b/r'
  $

But the same pattern with s/// warns​:

  $ /perl5/installed/bin/perl5.21.12 -wE '(my $x = "foo") = s/f/b/r'
  Useless use of non-destructive substitution (s///r) in void context at -e line 1.

This is an issue in blead and has been since 5.14.0 was
released. There is limited support for this warning if you write
things purely in void context​:

  $ /perl5/installed/bin/perl5.21.12 -wE 'my $x = "foo"; $x = s/f/b/r'
  Useless use of non-destructive substitution (s///r) in void context at -e line 1.
  $ /perl5/installed/bin/perl5.21.12 -wE 'my $x = "foo"; $x = tr/f/b/r'
  Useless use of non-destructive transliteration (tr///r) in void context at -e line 1.

But for some reason ($x = $y) =~ s///r is considered void context by
the detection code in op.c, but ($x = $y) =~ y///r is not.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.21.12:

Configured by avar at Tue Apr 28 15:40:55 UTC 2015.

Summary of my perl5 (revision 5 version 21 subversion 12) configuration:
  Commit id: b77ebf74c6d61f12ef717fd4bd6f765479481ca1
  Platform:
    osname=linux, osvers=3.14-2-amd64, archname=x86_64-linux-thread-multi
    uname='linux u.nix.is 3.14-2-amd64 #1 smp debian 3.14.13-2 (2014-07-24) x86_64 gnulinux '
    config_args='-DDEBUGGING=both -Doptimize=-ggdb3 -Dusethreads -Dprefix=/home/avar/perl5/installed -Dusedevel -des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-ggdb3',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion='', gccversion='4.2.1 Compatible Debian Clang 3.5.0 (tags/RELEASE_350/final)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -ggdb3 -L/usr/local/lib -fstack-protector-strong'



@INC for perl 5.21.12:
    /home/avar/perl5/installed/lib/site_perl/5.21.12/x86_64-linux-thread-multi
    /home/avar/perl5/installed/lib/site_perl/5.21.12
    /home/avar/perl5/installed/lib/5.21.12/x86_64-linux-thread-multi
    /home/avar/perl5/installed/lib/5.21.12
    /home/avar/perl5/installed/lib/site_perl
    .


Environment for perl 5.21.12:
    HOME=/home/avar
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/avar/local/bin:/home/avar/perl5/installed/bin:/home/v-perlbrew/perl5/perlbrew/bin:/home/v-perlbrew/perl5/perlbrew/perls/current/bin:/home/avar/local/bin:/home/avar/g/misc-scripts:/home/avar/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
    PERLDOC=-MPod::Text::Ansi
    PERL_BADLANG (unset)
    SHELL=/bin/bash

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

2 participants