zeek / spicy

C++ parser generator for dissecting protocols & files.
https://docs.zeek.org/projects/spicy
Other
243 stars 37 forks source link

Fix generated code for huge `const` collections. #1761

Closed bbannier closed 2 months ago

bbannier commented 2 months ago

When unrolling constructors of collections we previously would always capture explicitly so that container elements could reference other variables in the scope. This breaks for const variables which are emitted at non-local scope (into a namespace); the lambda performing the initialization would also be a non-local and non-local lambdas are not allowed to capture anything (they do not live in a scope after all).

This means that we cannot capture for such lambdas at all which seems to be an issue -- after all with that it seems impossible to support constructors of collections which reference other consts. Fortunately C++ lambdas at non-local scope implicitly capture other non-locals already and they do not need to be captured explictly. This allows for a rather simple fix.

Closes #1760.