C26811C26811
предупреждение C26811: время существования памяти, на которое ссылается параметр, <var> может заканчиваться временем возобновления соподпрограммы.warning C26811: Lifetime of the memory referenced by parameter <var> might end by the time the coroutine is resumed.
Предупреждение C26811 активируется, когда область памяти может быть использована после выхода из области действия в возобновляемой соподпрограмме.Warning C26811 is triggered when a memory region might be used after it went out of scope in a resumed coroutine.
ПримерExample
Следующий код создаст C26811.The following code will generate C26811.
#include <experimental/generator>
#include <future>
using namespace std::experimental;
// Simple awaiter to allows to resume a suspended coroutine
struct ManualControl
{
coroutine_handle<>& save_here;
bool await_ready() { return false; }
void await_suspend(coroutine_handle<> h) { save_here = h; }
void await_resume() {}
};
coroutine_handle<> g_suspended_coro;
std::future<void> async_coro(int &a)
{
co_await ManualControl{g_suspended_coro}; // @expected(26811), Lifetime of 'a' might end by the time this coroutine is resumed.
++a;
}