develooper Front page | perl.perl5.porters | Postings from May 2019

Name used only once warning issued in error?

From:
Adam Russell
Date:
May 12, 2019 19:02
Subject:
Name used only once warning issued in error?
Message ID:
BL0PR11MB32519FA58481891756F99236D40E0@BL0PR11MB3251.namprd11.prod.outlook.com
It seems that when a nested function created with local and used in a sort() call that the

"Name used only once" warning is issued erroneously.

Minimum code to reproduce is below. The warning given is 'Name "main::test_local_sub" used only once: possible typo at /tmp/temp.pl line 8.'

use strict;
use warnings;
##
#  Minimum code to reproduce.
##
sub test{
    #no warnings "once";
    local *test_local_sub = sub {
        return 0;
    };
    for(0..100){
        my @sorted = sort test_local_sub (1,2,3,4);
    }
}

Uncommenting the line
     #no warnings "once";
will silence the warning as expected.

This seems incorrect behavior, but is it? For example, this only seems to come up when used with sort. If simply called by itself no warning is issued.


$ perl -V
Summary of my perl5 (revision 5 version 28 subversion 0) configuration:

  Platform:
    osname=darwin
    osvers=18.2.0
    archname=darwin-thread-multi-2level
    uname='darwin adams-imac.fios-router.home 18.2.0 darwin kernel version 18.2.0: thu dec 20 20:46:53 pst 2018; root:xnu-4903.241.1~1release_x86_64 x86_64 '
    config_args='-de -Dprefix=/Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0 -Dusethreads -Aeval:scriptdir=/Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.14 -fno-strict-aliasing -pipe -fstack-protector-strong -I/opt/local/include -DPERL_USE_SAFE_PUTENV'
    optimize='-O3'
    cppflags='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.14 -fno-strict-aliasing -pipe -fstack-protector-strong -I/opt/local/include'
    ccversion=''
    gccversion='4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)'
    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 =' -mmacosx-version-min=10.14 -fstack-protector-strong -L/usr/local/lib -L/opt/local/lib'
    libpth=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib /usr/local/lib /opt/local/lib /usr/lib
    libs=-lpthread -lgdbm -ldbm -ldl -lm -lutil -lc
    perllibs=-lpthread -ldl -lm -lutil -lc
    libc=
    so=dylib
    useshrplib=false
    libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=bundle
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags=' -mmacosx-version-min=10.14 -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl):
  Compile-time options:
    HAS_TIMES
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_IMPLICIT_CONTEXT
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
    USE_REENTRANT_API
  Locally applied patches:
    Devel::PatchPerl 1.56
  Built under darwin
  Compiled at Mar 12 2019 11:04:00
  %ENV:
    PERLBREW_HOME="/Users/adamcrussell/.perlbrew"
    PERLBREW_MANPATH="/Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/man"
    PERLBREW_PATH="/Users/adamcrussell/perl5/perlbrew/bin:/Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/bin"
    PERLBREW_PERL="perl-5.28.0"
    PERLBREW_ROOT="/Users/adamcrussell/perl5/perlbrew"
    PERLBREW_SHELLRC_VERSION="0.86"
    PERLBREW_VERSION="0.86"
  @INC:
    /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib/site_perl/5.28.0/darwin-thread-multi-2level
    /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib/site_perl/5.28.0
    /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib/5.28.0/darwin-thread-multi-2level
    /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib/5.28.0





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About