Skip to content

Implicit capture of 'this' with a capture default of '=' is deprecated #654

@Alex2772

Description

@Alex2772

AUI and AUI-based code relies of implicit capture of this pointer which might lead to memory-related issues. Because of this behaviour, I can't do:

template<typename T>
struct ListView {
    contract::In<AVector<T>> items;
    contract::In<std::size_t> selectionId;
    contract::Slot<std::size_t> onSelectionChange;

    std::function<_<AView>(_<AView>)> body = ListViewDefaults::defaultBody;
    std::function<_<AView>(_<AView>)> scrollArea = ListViewDefaults::defaultScrollArea;

    _<AView> operator()() {
        return body(scrollArea(AUI_DECLARATIVE_FOR(i, items.value(), AVerticalLayout) { // <-- implcit capture of 'this'
            return Label { "{}"_format(i) };
        }));
    }
};

The code above emits a warning and crashes.

When building AUI on any compiler, it spams with this warning. I suggest rethinking the code that relies on reasonably deprecated implicit capture of 'this' and leverage this warning to error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions