Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What legal code could trigger C4523 "multiple destructors specified" Visual C++ warning?

According to MSDN, Visual C++ can emit C4523 warning 'class' : multiple destructors specified. How is such situation even possible?

I tried the following:

class Class {
    ~Class();
    ~Class(int);
};

which yields a destructor must have a 'void' parameter list error and C4523 warning and the following

class Class {
    ~Class();
    ~Class();
};

which yields member function already defined or declared error and the following

class Class {
    int ~Class();
    ~Class();
};

which yields a destructor cannot have a return type error.

So how do I have C4523 warning and no error?

like image 386
sharptooth Avatar asked Oct 27 '11 15:10

sharptooth


2 Answers

The following causes warning C4523 but it is also preceded by an error

struct Foo 
{
  ~Foo() {}
  ~Foo() const {}
};


error C2583: 'Foo::~Foo' : 'const' 'this' pointer is illegal for constructors/destructors
warning C4523: 'Foo' : multiple destructors specified
like image 59
Praetorian Avatar answered Oct 10 '22 04:10

Praetorian


Here's another example of multiple destructors being an error, not a warning:

class C
{
    ~C();
    ~C() volatile;
};
like image 27
Ben Voigt Avatar answered Oct 10 '22 03:10

Ben Voigt