Skip to content

Conversation

tonycoz
Copy link
Contributor

@tonycoz tonycoz commented 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

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
Copy link
Contributor

@leonerd leonerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I wonder if we want to put this into a 5.38.1 and a 5.36.2 in the near future? Otherwise, people will be writing code that happens not to provoke once warnings accidentally.

@tonycoz tonycoz merged commit 3c84977 into Perl:blead Jul 24, 2023
@tonycoz tonycoz added backport-5.36 backport-5.38 Change proposed for backport to maint-5.38 labels Jul 24, 2023
@tonycoz
Copy link
Contributor Author

tonycoz commented Jul 24, 2023

I've added this to both votes-5,36.xml and votes-5.38.xml in maint-votes.

Vote early, vote often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-5.36 backport-5.38 Change proposed for backport to maint-5.38

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants