

What does it mean when the compiler tells me that promise_type: is not a member...
source link: https://devblogs.microsoft.com/oldnewthing/20221212-00/?p=107582
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What does it mean when the compiler tells me that promise_type
: is not a member of coroutine_traits<void>
?

Raymond Chen
A customer using C++/WinRT found that their attempt to perform a co_await
on an IAsyncAction
failed to compile with the error
promise_type: is not a member of coroutine_traits<void>
What does this error mean? “We included <winrt/Windows.Foundation.h>
, which is allegedly how to fix this weird error message, but that didn’t fix it.”
This is a case of skipping the reading the explanation part of looking for a solution to your problem and skipping directly to the how to fix it part, without checking that the how to fix it applies to your specific situation. “Somebody called in to a car repair show because their car didn’t start, and the answer was that they had loose battery cables. My car won’t start, and I tightened the battery cables, but it didn’t fix it.” Well yeah, because you skipped over the part of the call where they did the troubleshooting.
As I noted in the earlier article, the co_await
keyword triggers the coroutine transformation which rewrites the function performing the co_await
into a state machine, and one of the pieces of the state machine is the promise_type
associated with the coroutine’s return type and parameters.
The coroutine_traits
specialization in the error message is coroutine_traits<void>
, so the return type is void
and there are no parameters. In other words, the function performing the co_await
looks something like this:
void DoSomething() { co_await MyFunctionAsync(); }
The C++/WinRT library provides support for producing coroutines returning winrt::Windows::Foundation::IAsyncAction
and related interfaces, as well as the special type winrt::fire_and_forget
. It does not, however, add support for coroutines returning void
.
The winrt/Windows.Foundation.h
header file defines the Windows Runtime coroutines, but void
is not a Windows Runtime coroutine type, so including Windows Runtime headers isn’t going to help. The code probably meant for DoSomething()
to return a type that can be used for coroutines, most likely IAsyncAction
or fire_and_forget
.
Now, you could always write your own support for producing coroutines returning void
, say, by having it behave roughly the same as fire_and_forget
. It’s not hard.
But probably not advisable.
Recommend
-
40
Currently , reactive is one of those trendy buzzwords in programming. Reactive is a word widely used as a prefix for “system” and “programming,” which both describe very different matters. ...
-
14
Does Inlined Mean Streamlined? Part 1: Escape Analysis Feb 24, 2019 | Richard Startin | javaanalysis
-
14
What does “8Ball is focused on designers” mean? Wednesday, September 15, 2004 There has been some discussions over the past couple of days around 8Ball (the next full release of Flash) and what its focus is going to be....
-
8
-
14
What the Heck Does “Disaggregated” Mean? Is there one good definition for disaggregation, in the context of networking? I’ve said in a number of my blogs that “commercial disaggregation”, the separation of software and hardware so y...
-
15
PHP 8: What does it mean to you?221 views•Feb 8, 2021200ShareSave ...
-
11
Congrats to compiler team member Aaron Hill Apr. 26, 2021 · Wesley Wiser on behalf of the compiler team I am pleased to a...
-
8
Promise compose compiler and imply when you'll change 🤞Subscribe to my newsletter and never miss my upcoming articlesListen to this articleYour browser does not support the...
-
3
Why does C++/WinRT say that first_interface is not a member of winrt::impl::interface_list<>? Raymond ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK