Skip to content

Permitted assignment to read-only capture in not-mutable lambda #95081

Closed
@Fedr

Description

This program

struct B {
    int i;
};

int foo() {
    auto [x] = B{1};
    [x]() {
        x = 2;
    }();
    return x;
}

is invalid because not-mutable lambda modifies its read-only capture x, and it is properly rejected by GCC and MSVC, but Clang erroneously admits it. Online demo: https://gcc.godbolt.org/z/46o6jad8n

Metadata

Assignees

No one assigned

    Labels

    accepts-invalidclang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partylambdaC++11 lambda expressions

    Type

    No type

    Projects

    • Status

      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions