Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expansion of global lambda expressions is broken #46

Closed
neobrain opened this issue Jul 15, 2018 · 2 comments
Closed

Expansion of global lambda expressions is broken #46

neobrain opened this issue Jul 15, 2018 · 2 comments
Labels
bug Something isn't working

Comments

@neobrain
Copy link

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;
}
;

@andreasfertig andreasfertig added the bug Something isn't working label Jul 15, 2018
andreasfertig pushed a commit that referenced this issue Jul 15, 2018
Once again the matchers caused trouble. The global autoDecl matcher did
also catch the lambda which resulted in a mess. This fix forwards
autoDecls into CodeGenerator as well and locks it against double match.
@andreasfertig
Copy link
Owner

Hi Tony,

thanks for reporting that with Tony-Tables :-) Surprisingly I have no test for a global Lambda.

The AST matchers are still a source of trouble. Next step is matching the whole TU. But that will take some time.

However, patch is on its way.

andreasfertig pushed a commit that referenced this issue Jul 15, 2018
Fixed issue #46: Lambda's in global scope.
@neobrain
Copy link
Author

Happy to help, thanks for the quick fix :)

andreasfertig pushed a commit that referenced this issue Jul 16, 2018
The change #46 makes it possible to remove the dedicated structured
bindings handler. The AutoStmtHandler can handle it as well, because all
structured bindings have an auto variable declaration. This removes more
or less duplicate code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants