https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90321

            Bug ID: 90321
           Summary: [C++17] GCC allows structured binding (decomposition)
                    of an object of type derived from a closure type
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: language.lawyer at gmail dot com
  Target Milestone: ---

The bug 78896 was fixed in r244909, so it is no longer possible to decompose a
closure itself, but deriving from a closure type makes it possible to access
closure members through an object of the derived type:


template<class F> struct hack : F { };
template<class F> hack(F) -> hack<F>;

int main()
{
    auto f = [x = 1, y = 2]() { };
    // auto [a, b] = f; // error: cannot decompose lambda closure type
'main()::<lambda()>'
    auto [a, b] = hack { f };

    return b; // returns 2
}


https://wandbox.org/permlink/1ucU0A9vFyAI9yYh

Reply via email to