microsoft / cppwinrt

C++/WinRT
MIT License
1.66k stars 239 forks source link

Bug: Clang build fails on coroutine type error #1283

Closed mimi89999 closed 1 year ago

mimi89999 commented 1 year ago

Version

v2.0.230225.1

Summary

MSYS2 Clang build fails with:

C:/Users/Michel/REDACTED/cppwinrt/winrt/Windows.UI.Core.h:3496:25: error: no matching function for call to object of type 'const impl::coroutine_handle<>' (aka 'const coroutine_handle<void>')
                        handle();
                        ^~~~~~
C:/msys64/clang64/include/c++/v1/experimental/coroutine:106:10: note: candidate function not viable: 'this' argument has type 'const impl::coroutine_handle<>' (aka 'const coroutine_handle<void>'), but method is not marked const
    void operator()() { resume(); }
         ^

Reproducible example

No response

Expected behavior

No response

Actual behavior

No response

Additional comments

No response

kennykerr commented 1 year ago

You may be using an older or untested version. The CI build validates a few scenarios with different compilers. It may help narrow down what might be wrong:

https://github.com/microsoft/cppwinrt/actions/runs/4325498719/jobs/7551737827

sylveon commented 1 year ago

It seems you are using experimental coroutines (as shown by the path to the coroutines header in the error). Experimental coroutines where only ever supported with MSVC, and unless you manually defined _RESUMABLE_FUNCTIONS_SUPPORTED, I don't think cppwinrt even attempts to use experimental coroutines on Clang.

You should be able to use C++20 coroutines however.

alvinhochun commented 1 year ago

You need to pass -std=c++20 (or -std=gnu++20) to clang++ to enable C++20.

The error is just confusing. LLVM's libc++ does have experimental/coroutine but that implementation is different from the one from the MSVC STL so it's really untested, and I don't think it's worth the trouble to try to make it compatible. There should probably be a && defined(_MSC_VER) here: https://github.com/microsoft/cppwinrt/blob/629f9e7659a7dae408606456cf8a9f05ff2f4511/strings/base_includes.h#L58

Hypothetically, if the user doesn't need to use coroutine at all, is it possible to make cppwinrt usable in C++17 without coroutine support?

sylveon commented 1 year ago

Hypothetically, if the user doesn't need to use coroutine at all, is it possible to make cppwinrt usable in C++17 without coroutine support?

It used to be possible, I don't remember when that changed exactly.

mimi89999 commented 1 year ago

Thanks. I switched to C++20 and it build!