develooper Front page | perl.perl5.porters | Postings from January 2016

[perl #6997] "Useless use of concatenation" warning not triggered bymultiple concatenations.

Thread Previous | Thread Next
From:
Matthew Horsfall via RT
Date:
January 16, 2016 21:40
Subject:
[perl #6997] "Useless use of concatenation" warning not triggered bymultiple concatenations.
Message ID:
rt-4.0.18-15839-1452980408-541.6997-14-0@perl.org
On Mon May 14 21:22:06 2001, pnewton@gmx.de wrote:
> $ ./perl -w -e '($a,$b)=(42)x2; $a . $b'
> Useless use of concatenation (.) or string in void context at -e line 1.
> $ ./perl -w -e '($a,$b,$c)=(42)x3; $a . $b . $c'
> (nothing)
> 
> To me, the second concatenation is also in void context.

Agreed.

This seems to stem from some old code that I'm not sure is necessary any more.

Perl_ck_concat does:

    if (kid->op_type == OP_CONCAT && !(kid->op_private & OPpTARGET_MY) &&
            !(kUNOP->op_first->op_flags & OPf_MOD))
        o->op_flags |= OPf_STACKED;

But why does it do this?

Removing Perl_ck_concat makes $a . $b . $c warn properly, and doesn't break the test suite (legit, right?).

Compare (pre-patch) how multiple add ops are constructed versus multiple concat ops:

  mhorsfall@tworivers:~/p5/perl$ perl -MO=Concise,-exec -e '$x + $a'
  1  <0> enter 
  2  <;> nextstate(main 1 -e:1) v:{
  3  <#> gvsv[*x] s
  4  <#> gvsv[*a] s
  5  <2> add[t3] vK/2
  6  <@> leave[1 ref] vKP/REFC
  -e syntax OK
 mhorsfall@tworivers:~/p5/perl$ perl -MO=Concise,-exec -e '$x + $a + $a'
  1   <0> enter 
  2  <;> nextstate(main 1 -e:1) v:{
  3   <#> gvsv[*x] s
  4   <#> gvsv[*a] s
  5  <2> add[t3] sK/2
  6  <#> gvsv[*a] s
  7  <2> add[t5] vK/2
  8  <@> leave[1 ref] vKP/REFC
  -e syntax OK

  mhorsfall@tworivers:~/p5/perl$ perl -MO=Concise,-exec -e '$x . $a'
  1  <0> enter 
  2  <;> nextstate(main 1 -e:1) v:{
  3  <#> gvsv[*x] s
  4  <#> gvsv[*a] s
  5  <2> concat[t3] vK/2
  6  <@> leave[1 ref] vKP/REFC
  -e syntax OK
  mhorsfall@tworivers:~/p5/perl$ perl -MO=Concise,-exec -e '$x . $a . $a'
  1  <0> enter 
  2  <;> nextstate(main 1 -e:1) v:{
  3  <#> gvsv[*x] s
  4  <#> gvsv[*a] s
  5  <2> concat[t3] sK/2
  6  <#> gvsv[*a] s
  7  <2> concat[t5] vKS/2         <-- OPf_STACKED 
  8  <@> leave[1 ref] vKP/REFC

With Perl_ck_concat, the final concat is modified to be OPf_STACKED, which causes the void warning to not trigger.

Is . fundamentally different than + in some way I don't know, or is this just old code that's no longer needed?

Possible patch attached.

-- Matthew Horsfall (alh)

Thread Previous | Thread Next


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