summaryrefslogtreecommitdiff
path: root/ACE/tests/Compiler_Features_09_Test.cpp
blob: c765724237a4d3ce3e24afa04763dee1ff331208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
 * @file
 *
 * This program checks if the compiler / platform supports the
 * std::auto_ptr<> correctly.  The motivation for this test was a discussion
 * on the development mailing list, and the documentation was captured
 * in:
 *
 *   http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=3715
 */

#include "test_config.h"

// The first part of the test is to compile this line.  If the program
// does not compile the platform is just too broken.
#include <memory>
#include <utility>

// For extra challenge, we use the anonymous namespace
namespace
{
/**
 * @class Base
 */
class Base
{
public:
  Base()
  {
    constructors++;
  }
  Base(Base const & )
  {
    constructors++;
  }
  ~Base()
  {
    destructors++;
  }

  static int constructors;
  static int destructors;
};

int Base::constructors = 0;
int Base::destructors = 0;

class Derived : public Base
{
public:
  Derived()
    : Base()
  {}
};
}

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT("Compiler_Features_09_Test"));

  // As usual, the exit status from the test is 0 on success, 1 on
  // failure
  int status = 0;

  // ... this works with the ACE version of auto_ptr (well, the
  // namespace is broken, but you get the idea) ...
  std::unique_ptr<Base> x(new Base);
  std::unique_ptr<Derived> y(new Derived);

  // ... with a compliant implementation of std::auto_ptr<> you should be
  // able to write:
  //    x = y;
  // but the Solaris compiler was broken as of August, 2009!!  So you have
  // to work around in the following way.  This compiler is important
  // enough for the ACE community, so we have to support this broken
  // configuration ...
  x.reset(y.release());

  // ... there should be just one destruction so far ...
  if (Base::destructors != 1)
    {
      status = 1;
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("Destructor count off, expected 1, found %d\n"),
                 Base::destructors));
    }

  std::unique_ptr<Base> z;
  z = std::move(x);
  if (Base::destructors != 1)
    {
      status = 1;
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("Destructor count off, expected 1, found %d\n"),
                 Base::destructors));
    }
  if (x.get())
    {
      status = 1;
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("x contents should have been transferred\n")
                 ));
    }

  ACE_END_TEST;
  return status;
}