Skip to content

A minor attention to lambda expressions #344

@coralkashri

Description

@coralkashri

It's not a bug, but an extra ; empty line when using lambda expressions without any usage inside a scope:

#include <iostream>

int main() {
  []() {};
  return EXIT_SUCCESS;
}

Will generate:

#include <iostream>

int main()
{
    
  class __lambda_4_3
  {
    public: 
    inline /*constexpr */ void operator()() const
    {
    }
    
    using retType_4_3 = void (*)();
    inline /*constexpr */ operator retType_4_3 () const noexcept
    {
      return __invoke;
    };
    
    private: 
    static inline void __invoke()
    {
    }
    
    
    public:
    // /*constexpr */ __lambda_4_3() = default;
    
  } __lambda_4_3{};
  
  ; // <------------------------------- This one is not necessary
  return 0;
}

When there is a usage for the lambda, this line if for the usage. For example, for [](){} (); we'll get there:

__lambda_4_3.operator()();

Or for an assignment:

__lambda_4_12 a = __lambda_4_12{};

Just a minor attention :)

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