https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122994
Bug ID: 122994
Summary: [Modules] lambda expression in global variable
initializer is considered to expose TU-local types
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mawww at kakoune dot org
Target Milestone: ---
This code fails to compile with `-std=c++20 -fmodules`
```
export module m;
namespace {
struct A {};
auto f = []{ A{}; };
}
struct B { B(void (*func)()) {} };
B works{f};
B fails{[]{ A{}; }};
```
The error is "error: '<lambda()>' exposes TU-local entity 'struct
{anonymous}::A'"
According to https://ww.cppreference.com/w/cpp/language/tu_local.html
> A declaration is an exposure if it either names a TU-local entity, ignoring
>
> the function-body for a non-inline function or function template (but not
> the deduced return type for a (possibly instantiated) definition of a
> function with a declared return type that uses a placeholder type),
> the initializer for a variable or variable template (but not the
> variable’s type),
> friend declarations in a class definition, and
> any reference to a non-volatile const object or reference with internal
> or no linkage initialized with a constant expression that is not an odr-use,
>
> or defines a constexpr variable initialized to a TU-local value
This seems to imply that the code is well-formed as the initializer should be
ignored, I tried to go through the standard draft to get more precise
references but failed to find the relevant rules there.
This test case is also in https://godbolt.org/z/Gn3b6s9M5