虚函数的异常规范与重写函数的异常规范不兼容

时间:2013-11-22 18:35:28

标签: c++ exception inheritance c++11 virtual

我使用intel的icpc(版本14.0.1,使用-std=c++11)收到此错误消息,而clang(版本3.4)和gcc(版本4.8.1)都很高兴。典型的违规代码是:

#include <vector>
namespace test {
  struct A
  {
    virtual bool foo(std::size_t) const = 0;
    virtual ~A() = default;
  };

  struct B
  : A
  {
    const std::vector<double> V;
    const double X;
    bool foo(std::size_t i) const { return V.at(i) > X; }
    virtual bool bar(std::size_t i) const { return V.at(i) < X; }
    B(double x, std::vector<double> const &v)
      : V(v), X(x) {}
    ~B() = default;
  };
}

由于test::A是抽象的,因此最好有一个虚拟析构函数。然而, 关于

,icpc抱怨(编译错误而不是警告)
  

虚函数“test :: B ::〜B”的异常规范是   与重写函数“test :: A ::〜A”

的函数不兼容

我认为所有这些都是intel编译器的一些错误。正确的吗?

PS。在C ++ 11之前,我注意到了一个相关的question。当throw被弃用(并被noexcept替换)时,我真的很关心C ++ 11。

0 个答案:

没有答案