aui icon indicating copy to clipboard operation
aui copied to clipboard

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

Open Alex2772 opened this issue 2 months ago • 0 comments

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.

Alex2772 avatar Nov 07 '25 13:11 Alex2772