是什么决定了runtime_error是否为__nothrow_copy_constructible?

时间:2018-05-10 20:32:43

标签: c++ exception runtime-error

我有一个继承自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]

此检查的相关信息为available here。 我相信我理解该页面上的信息。 特别是,我认为相关信息是std::runtime_error及其子类应具有特征is_nothrow_copy_constructible

我无法协调以下内容。

场景1:

compiler explorer上的以下代码演示了使用gcc 5.x和更新版本编译时的类is_nothrow_copy_constructible,但是在使用gcc 4.x编译时没有。

场景2:

在我的笔记本电脑上,运行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的单个配置。 这包括使用与libstdc++.so.6.0.25链接的gcc 5,gcc 6,gcc 7,clang 4和clang 5。

以下是specific travis build log演示测试失败,使用gcc 5,与libstdc++.so.6.0.25相关联。  (custom_error仅重命名为Exception。)

问题:

有人可以向我解释一下可以确定班级is_nothrow_copy_constructible吗?

对我来说,上面的结果表明答案可能会有所不同:

  • 实施
  • 编译器和
  • 标准库版本

是完全相同的。

0 个答案:

没有答案
相关问题