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

[doc] use v5.36, only partially enables warnings #21271

Closed
druud opened this issue Jul 20, 2023 · 2 comments · Fixed by #21284
Closed

[doc] use v5.36, only partially enables warnings #21271

druud opened this issue Jul 20, 2023 · 2 comments · Fixed by #21284

Comments

@druud
Copy link
Contributor

druud commented Jul 20, 2023

perl5360delta says:

Furthermore, use v5.36 will also enable warnings as if you'd written use warnings.

but the 'once' warning is an exception:

perl -e'use v5.36; no strict; print $i' 
Use of uninitialized value $i in print at -e line 1.

vs:

perl -e'use v5.36; no strict; use warnings; print $i'
Name "main::i" used only once: possible typo at -e line 1.
Use of uninitialized value $i in print at -e line 1.
@Leont
Copy link
Contributor

Leont commented Jul 22, 2023

I guess this is a side-effect of the optimizer, because adding almost any use line (other than strict?) will make the once warning reappear.

tonycoz added a commit to tonycoz/perl5 that referenced this issue Jul 24, 2023
There's two parts to producing the "used only once" warning:

1. In a lexical scope with WARN_ONCE enabled, new GVs are
created with the GVf_MULTI flag off, a second mention of such a
name will set that flag.

2. After compilation, if G_WARN_ONCE is set in PL_dowarn, the entire
package tree is walked to report names which don't have GVf_MULTI set.

In this case G_WARN_ONCE wasn't being set, so the second part didn't
happen.

This flag is global, so using any other module that happened to
enable the WARN_ONCE flag (anything that does C<use warnings;>)
would allow warnings to be produced after compilation.

Fixes Perl#21271
@tonycoz
Copy link
Contributor

tonycoz commented Jul 24, 2023

Perl_utilize() isn't setting G_WARN_ONCE in PL_dowarn, which triggers the scan for "used only once" symbols after compilation.

I expect the other module you were useing was doing a use warnings; which would set G_WARN_ONCE when warnings.pm set ${^WARNING_BITS}.

tonycoz added a commit that referenced this issue Jul 24, 2023
There's two parts to producing the "used only once" warning:

1. In a lexical scope with WARN_ONCE enabled, new GVs are
created with the GVf_MULTI flag off, a second mention of such a
name will set that flag.

2. After compilation, if G_WARN_ONCE is set in PL_dowarn, the entire
package tree is walked to report names which don't have GVf_MULTI set.

In this case G_WARN_ONCE wasn't being set, so the second part didn't
happen.

This flag is global, so using any other module that happened to
enable the WARN_ONCE flag (anything that does C<use warnings;>)
would allow warnings to be produced after compilation.

Fixes #21271
steve-m-hay pushed a commit that referenced this issue Oct 6, 2024
There's two parts to producing the "used only once" warning:

1. In a lexical scope with WARN_ONCE enabled, new GVs are
created with the GVf_MULTI flag off, a second mention of such a
name will set that flag.

2. After compilation, if G_WARN_ONCE is set in PL_dowarn, the entire
package tree is walked to report names which don't have GVf_MULTI set.

In this case G_WARN_ONCE wasn't being set, so the second part didn't
happen.

This flag is global, so using any other module that happened to
enable the WARN_ONCE flag (anything that does C<use warnings;>)
would allow warnings to be produced after compilation.

Fixes #21271

(cherry picked from commit 3c84977)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants