跳转至

ev-stdexec-copy-elision-member-awaitable-002

字段 值
项目 NVIDIA/stdexec
固定 commit 6d7ad689f4d4
路径 include/stdexec/__detail/__connect_awaitable.hpp
行段 L169-L176
特性 保证的复制消除
许可证 Apache-2.0
代码来源 项目源码
级别 manual
审核 zyuhao7 @ 2026-10-27
测试代码 否
发现方式 manual

用法

注释说明成员以函数返回值直接初始化本应触发强制复制消除,GCC 未实现时退回手动生命周期管理

为什么典型

把规则用在成员初始化上;同时展示编译器缺陷迫使库作者准备回退路径。

摘录

          // GCC doesn't like initializing __awaitable_ or __awaiter_ in the member initializer
          // clause when the result of __get_awaitable or __get_awaiter is immovable; it *seems*
          // like direct initialization of a member with the result of a function ought to trigger
          // C++17's mandatory copy elision, and both Clang and MSVC accept that code, but using
          // __manual_lifetime works around the issue.
          __awaitable_.__construct_from(__get_awaitable,
                                        static_cast<_Awaitable&&>(__source),
                                        __coro.promise());

备注

生产路径;协程 awaitable 包装的构造逻辑,用 __manual_lifetime 绕过 GCC 的复制消除缺陷。

查看固定 commit 源码 · 返回证据索引