https://bugs.llvm.org/show_bug.cgi?id=41765

            Bug ID: 41765
           Summary: Clang allows structured binding of a closure object
                    inside its operator()
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P
         Component: C++'17
          Assignee: unassignedclangb...@nondot.org
          Reporter: language.law...@gmail.com
                CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
                    llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk

Since https://wg21.link/P0969R0 (implemented in [1]) structured binding of a
class does not rely on publicity of the members, only accessibility. So it is
possible to decompose a closure from the inside of its operator().

int main()
{
        int x = 1, y = 2;
        auto f = [&](auto self) {
                (void)x; (void)y; // make 'em used!
                auto& [a, b] = *self; // a == 1, b == 2. Depends on the
previous line.
                return b - a;
        };
        return f(&f); // returns 1
}

https://wandbox.org/permlink/CVlWjnDHPPMbRT2r

[1]
https://github.com/llvm/llvm-project/commit/5c9b3b757623e6bea5b4929b2046a565ee2d11bc

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to