c++ - 什么决定 runtime_error 是否为_nothrow_copy_constructible?
问题描述
我有一个异常类的实现,它继承自std::runtime_error
:
class custom_error : public std::runtime_error {
public:
explicit custom_error(const std::string &arg)
: std::runtime_error(arg){};
~custom_error() noexcept override = default;
};
此实现尽可能libstdc++
与std::runtime_error
.
在此代码上运行 clang-tidy 时(在某些情况下 - 见下文),会发出以下警告:
warning: thrown exception type is not nothrow copy constructible [cert-err60-cpp]
有关此检查的相关信息可在此处获得。我相信我了解该页面上的信息。特别是,我相信相关信息是 astd::runtime_error
及其子类应该具有 trait is_nothrow_copy_constructible
。
我无法协调以下内容。
场景一:
编译器资源管理器上的以下代码演示了is_nothrow_copy_constructible
使用 gcc 5.x 和更高版本编译的类,但不是使用 gcc 4.x 编译的类。
场景二:
在我的笔记本电脑上,运行 Ubuntu 18.04,is_nothrow_copy_constructible
当使用 gcc 5、gcc 7、clang 3.8、clang 5 和 clang 6 编译时,同一个类也与libstdc++.so.6.0.25
.
场景 3:
在运行 Ubuntu 14.04 实例的 travis-ci 上,我找不到相同类的单个配置is_nothrow_copy_constructible
。这包括使用 gcc 5、gcc 6、gcc 7、clang 4 和 clang 5,链接到libstdc++.so.6.0.25
.
这是一个特定的 travis 构建日志,展示了测试失败,它使用 gcc 5,链接到libstdc++.so.6.0.25
. (custom_error
简单地重命名Exception
。)
问题:
有人可以向我解释什么可以确定是否上课is_nothrow_copy_constructible
?
对我来说,上述情况表明,在以下情况下,答案可能会有所不同:
- 执行
- 编译器,和
- 标准库版本
是相同的。
解决方案
推荐阅读
- apache-spark - PyCharm - 连接到 oracle DB 时找不到驱动程序错误
- flutter - Flutter:如何确保从异步函数正确初始化变量?
- android - Tmap 和 TWebBrowser 重叠 TMultiview,适用于 Android 和 Windows
- java - 如何在过滤器中添加请求标头并在控制器中获取该标头
- python - 由于分类交叉熵损失,图形断开错误
- vba - Ms Access 表或查询
- spring - AUTHENTICATION_FAILURE AuditEvent 远程地址丢失
- docker - 使用容器化 DNS 服务器的 Docker 容器到容器 DNS
- python-3.x - ctypes 不释放字符串缓冲区?
- postgresql - 来自单个数据库的表在创建时自动复制到其他数据库 - PostgreSQL