04-unique_ptr3_bad.cpp 780 Bytes
#include <memory>
#include <iostream>
using namespace std;

class Example
{
  public:

  Example()
  {
    cout << "Example::Example()" << endl;
  }

  Example(int a)
  {
    cout << "Example::Example(" << a << ")" << endl;
  }

  ~Example()
  {
    cout << "Example::~Example()" << endl;
  }
};

int genexc()
{
  cout << "genexc()" << endl;
  throw 0;
  return 0;
}

void fun1(const unique_ptr<Example>& ptr, int b)
{
  
}

void fun2(int b, const unique_ptr<Example>& ptr)
{
  
}

int main()
{
cout << "One:" << endl;
try {
  fun1(unique_ptr<Example>(new Example), genexc()); // problem: evaluation order undefined
} catch (...)
{
}

cout << "Two:" << endl;
try {
  fun2(genexc(), unique_ptr<Example>(new Example(3))); // problem: evaluation order undefined
} catch (...)
{
}

}