首页 > 解决方案 > 什么决定 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

对我来说,上述情况表明,在以下情况下,答案可能会有所不同:

是相同的。

标签: c++exceptionruntime-error

解决方案


推荐阅读