PR c++/94147 - mangling of lambdas assigned to globals
This patch implements Jason's suggestion of pushing a lambda scope
when parsing a global variable initializer. That bit worked fine, but
happened to cause g++.dg/opt/dump1.C to not give any
used-but-not-defined warnings.
The reason was no_linkage_check, which considers any lambda that has
an extra-scope to have linkage. Which is technically correct. Except
that we think that all types that have linkage have external linkage.
Our representation of linkage and visibility is somewhat inaccurate,
particularly when it comes to types. We have TREE_PUBLIC,
DECL_EXTERNAL, DECL_VISIBILITY, DECL_COMDAT, DECL_NOT_REALLY_EXTERN.
It could really do with a through cleanup, but that won't be a simple
task.
The best I could come up with was seeing if the extra scope was a
VAR_DECL, and if that was TREE_PUBLIC and the var was inline (its
COMDATness is sadly not set at that point) or a template
instantiation, then the lambda had linkage. Otherwise it's as-if it
has no-linkage from the POV of compiler internals.
This is an ABI change (so we should document it), but it's changing
mangling from an unpredictable (in practice) counter, to something the
ABI defines. So I'm not concerned about mangling-changed warnings, or
preserving the broken mangling under some ABI selection flag. Code
that did this worked by accident within a single TU. It'll continue
to work by design there, and across TUs.
* parser.c (cp_parser_init_declarator): Namespace-scope variables
provide a lambda scope.
* tree.c (no_linkage_check): Lambdas with a variable for extra
scope have a linkage from the variable.