mercredi 30 août 2017

Destructor in derived class marked as noexcept(false)

There is following code:

class Member
{
public:
  ~Member() noexcept(false) {}
};

class A
{
public:
  virtual ~A() {}
};

class B : public A
{
public:
  Member m;
};

The error is:

main.cpp:13:7: error: looser throw specifier for ‘virtual B::~B() noexcept (false)’
 class B : public A
       ^
main.cpp:10:11: error:   overriding ‘virtual A::~A() noexcept’
   virtual ~A() {}
           ^

Why does the destructor in class B is marked as noexcept(false)? It seems that it somehow gets it from Member class. It was compiled by g++ 6.3.

Aucun commentaire:

Enregistrer un commentaire