Skip to content

Wrong linkage and mangling for class-scope lambda expressions #143218

Open
@zygoloid

Description

@zygoloid

C++ allows lambdas to be defined directly in class scope. When this happens, the lambda should have the same linkage as the class, as it would if it appeared in a default argument or default member initializer or function body within the class, and it should be mangled with the enclosing class as the mangling context.

Example:

template <auto L> struct B {};
struct A { B<[] { return 0; }> b; };
void f(decltype(A::b) x) {}

This should result in an external linkage symbol for f being emitted. But Clang incorrectly gives the lambda internal linkage and a mangling involving $_3, resulting in no definition for f being emitted.

GCC appears to have implemented this in version 15 onwards. (In version 14 and before, GCC used internal linkage for the lambda, as Clang does.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"lambdaC++11 lambda expressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions