Skip to content

Expansion of global lambda expressions is broken #46

@neobrain

Description

@neobrain

Lambda expressions at global scope generate unintelligible output. C++ Insights is supposed to replace them with equivalent, explicit class definitions, but this only seems to work properly for lambda expressions defined inside a function.

The following table illustrates the output for a locally defined lambda (fine) vs. two instances of global lambdas (broken).

Input C++ Insights
int main() {
    auto x = [a=5](int b) {
        return b*a;
    };
}
int main() {
  class __lambda_10_14 {
    public: inline /*constexpr */ int operator()(int b) const {
      return b * a;
    }
    private:
    int a;
    public:
    __lambda_10_14(int _a)
        : a{_a}
        {}
  };
 __lambda_10_14 x = __lambda_10_14{5};
}

auto x = []() {
    return 5;
};
__lambda_1_10 x = /* public: inline ~() noexcept; */
static inline int __invoke();
         ;
auto x2 = [a=5](int b) {
    return b*a;
};
__lambda_5_11 x2 = /* public: inline ~() noexcept; */
[inta=5](int binline constexpr int operator()(int b) const
{
return b * a;
}
;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions