Skip to content

Lambda Capture by value for reference typed variables. #64

@textshell

Description

@textshell

According to http://eel.is/c++draft/expr.prim.lambda#capture-10 and cppreference.org lambdas seems to capture references as copies of the decayed type.

But cppinsights does not agree given:

#include <string>

void func(const std::string& arg) {
 
  [arg] {
    return arg.size();
  };
}

int main() {
  std::string b;
  
  func(b);
}

It generates:

    const std::basic_string<char, std::char_traits<char>, std::allocator<char> > & arg;
    
    public: __lambda_5_3(const std::basic_string<char, std::char_traits<char>, std::allocator<char> > & _arg)
    : arg{_arg}
    {}

Where i would expect based on the linked section that it would produce:

    const std::basic_string<char, std::char_traits<char>, std::allocator<char> > arg;

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