Skip to content

Nested lambdas yield broken tokens #3

@Alcaro

Description

@Alcaro

Found this on LLVM Weekly. Neat project.

Unfortunately, lambda handling seems quite buggy. For example:

void x()
{
  auto a = [](){
    [](){};
  };
}
void x()
{

   class __lambda_3
   {
     public: inline /*constexpr */ void operator()() const
     {
       __lambda_4;
     }
     
   };
   
   
   class __lambda_4
   {
     public: inline /*constexpr */ void operator()() const
     {
     }
     
   };
   
     __lambda_3 a = __lambda_4{}da_3{};
}

I'm not sure what __lambda_3; in operator() is supposed to do, and __lambda_4{}da_3{} is nonsense.

I suspect you're replacing the substring at [4,7) with something longer, then doing another replacement on the same line, without adjusting the offsets to account for the previous replacement. This yields lots of strange output (another example: removing auto a = makes it emit lambdas in the output), but I think most or all of it is all the same root cause.

(Additionally, two lambdas on the same line expand to two classes with the same name. Append column number to subsequent ones, maybe?)

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