Tracking construction and destruction of automatic objects in a function that throws exception

Question | Apr 28, 2016 | hkumar 

Look at this C++ code:

struct A {
    A()  { tracker +=1; }
    ~A() { tracker -=1; }

    static int tracker;
};

int A::tracker = 0;

void foo(int x) {
    A a1;
    if(!x)
        throw "error";
    A a2;
}

Now call foo() in a try..catch block like this:

try { 
  foo(0); 
} catch(...) {}

What is the value of A::tracker now?

2015 nextptr