警告:忽略模板参数上的属性..在 std::unique_ptr (-wignore 属性)的声明中
Warning: ignoring attributes on template argument... in declaration of std::unique_ptr (-Wignored-attributes)
使用此处解释的模式如下:
auto action =
std::unique_ptr< posix_spawn_file_actions_t, decltype(&posix_spawn_file_actions_destroy) >
{ new posix_spawn_file_actions_t(), posix_spawn_file_actions_destroy };
在 GCCv10.1.0
-std=c++20
中触发[-Wignored-attributes]
:
warning: ignoring attributes on template argument ‘int (*)(posix_spawn_file_actions_t*) noexcept’
| std::unique_ptr<posix_spawn_file_actions_t, decltype(&posix_spawn_file_actions_destroy)>
| ^
为什么?应该忽略它还是有办法调整代码?
这是说你忽略了函数指针不会抛出的事实。
代码存在其他错误,例如更新未通过删除清理的指针。
在 c++14 或更高版本中,我使用
template<auto x> using kval_t=std::intergral_constant<std::decay_t<decltype(x)>,x>;
template<auto x> constexpr kval_t<x> kval={};
然后,您可以:
auto action =
std::unique_ptr< posix_spawn_file_actions_t, kval_t<posix_spawn_file_actions_destroy> > =
{ new posix_spawn_file_actions_t() };
但是new
这里可能是创建posix_spawn_file_actions_t
的错误方法。
这会将函数指针存储在编译时常量中,并可能消除该警告。
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- C++概念:如何使用'concept'检查模板化结构的属性?
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- CLANG 编译器 说:变量"PTR"可能未初始化
- Qt Quick-如何仅从c++代码与qml属性交互
- 用概念检查属性的类型
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- C++如何将同一类的实例作为属性
- 将 ptr 传递给 ptr 到 A 作为参数传递给 A 的函数是不好的做法吗?
- 按多个属性排序
- 主函数参数的属性
- "perf_event_attr"结构的"read_format"属性的选项到底是什么?
- C++删除未使用的类属性会导致 std::logic_error
- 无法使用 SWIG 在 Python 中实例化C++类(获取属性错误)
- 使用内存地址访问结构的属性值
- C++调用具有 *this 属性的单个帮助程序函数