Skip to content

Structured bindings and captures issue with Clang #659

@hummeleBop

Description

@hummeleBop

Structured bindings cannot be names of variables, it is making them not capturable, at least in clang.

I get the following error:

Generated Files\winrt/Windows.Foundation.h(3769,29): error: reference to local binding 'delegate'
      declared in enclosing function 'winrt::when_any'
            async.Completed(delegate);
                            ^
Generated Files\winrt/Windows.Foundation.h(3765,15): note: 'delegate' declared here
        auto [delegate, shared] = impl::make_delegate_with_shared_state<impl::async_completed_handler_t<T>>(...
              ^
1 error generated.

A possible fix could be:

diff --git a/- "b/.\\out-herschel-uwp\\Generated Files\\winrt\\Windows.Foundation.h"
index 0000000..3cef95c 100644
--- a/-
+++ "b/.\\out-herschel-uwp\\Generated Files\\winrt\\Windows.Foundation.h"
@@ -3764,7 +3764,7 @@ WINRT_EXPORT namespace winrt

         auto [delegate, shared] = impl::make_delegate_with_shared_state<impl::async_completed_handler_t<T>>(shared_type{});

-        auto completed = [&](T const& async)
+        auto completed = [delegate = delegate](T const& async)
         {
             async.Completed(delegate);
         };
@@ -3777,4 +3777,3 @@ WINRT_EXPORT namespace winrt
     }
 }
 #endif

I don't know if the fix is correct or not, but it's useful as an hint.

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