I was recently surprised about how a chunk of code compiled and
executed, which lead me to wonder what would be "correct" from a C++
standards perspective. (I don't need help to arrive at sensible code,
this is for academic interest only...)
--
#include <iostream>
using namespace std;
class A {
public:
A() { cerr << "CA"; }
virtual ~A() =0; };
class B : public A {
public:
B(bool a) { if (a) throw a; }
~B() { cerr << "DA"; } };
int main(int c,char *v[])
{
try { B b(c==1); } catch(bool x) { cerr << "catch" << endl; }
return 0;
}
--
I'm interested to know:
* While this obviously compiles, is it complete - i.e. should it link?
* Should the fact that A has a pure virtual destructor influence
whether or not B's destructor is called in the context of exception
'a'?
* Have either of the above two questions different answers if one
looks from the perspective different C++ standards vintages?