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
substr in sub call doesn't respect lexical "no warnings" #14399
Comments
From michael.j.carman@gmail.comThis is a bug report for perl from michael.j.carman@gmail.com, When substr is used as an argument to a sub call and the substring is outside of use strict; { sub foo { Under v5.16.1 this emits substr outside of string at c:\temp\foo.pl line 10. In order to suppress the warning the "no warnings 'substr'" line must be moved This behavior appears to be related to changes in v5.16.0 that made a substr Passing a substring of a read-only value or a typeglob to a function The same thing happens with the "substr outside of string" error. If the In 5.10.1 the code sample dies on the call to substr but correctly reports the Flags: Site configuration information for perl 5.16.1: Configured by gecko at Thu Aug 30 20:04:55 2012. Summary of my perl5 (revision 5 version 16 subversion 1) configuration: Platform: Locally applied patches: @INC for perl 5.16.1: Environment for perl 5.16.1: |
From @cpansproutOn Mon Jan 05 11:44:51 2015, michael.j.carman@gmail.com wrote:
I’m not sure there is any way to fix this without breaking other things. You see, the substr() call creates a special magical scalar and that scalar is passed to foo(). It is only when you try to read from that scalar (or assign to it) that perl finds out that it represents a substring outside of the target string. It is necessary for it to work this way in the case of variables, as in foo(substr($bar, 4, 6)), because the value of $bar may change before the substring is taken. If we make this work differently for constant targets and variable targets, then we get the warning occurring in different places; it would be less predictable. So it’s six of one or half a dozen of the other. -- Father Chrysostomos |
The RT System itself - Status changed from 'new' to 'open' |
From michael.j.carman@gmail.comOn Mon Jan 05 17:59:38 2015, sprout wrote:
I wouldn't expect it to work differently for variables and constants; I just happened to use a constant in my example. In the real code where I discovered the issue I was using a variable. (The constant case seems unlikely for real code.) I don't know enough about the internals to know how to fix it, but presumably any attempt would require the magic scalar to include a reference to the warnings flags from the scope where the substr appears. That said, I can imagine wanting different behavior depending on whether the substr is used as an rvalue or an lvalue. For my example (rvalue) usage I'd expect the error and "no warnings" to apply in the scope where the substr call appeared. For lvalue usage it would probably make more sense to report/warn from the scope where the magic scalar is used. :( |
Migrated from rt.perl.org#123552 (status was 'open')
Searchable as RT123552$
The text was updated successfully, but these errors were encountered: