[llvm-bugs] [Bug 41765] New: Clang allows structured binding of a closure object inside its operator()

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 6 02:21:49 PDT 2019


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: unassignedclangbugs at nondot.org
          Reporter: language.lawyer at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190506/c64e099f/attachment.html>


More information about the llvm-bugs mailing list