Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Compiler_Features_09_Test.cpp
blobc94d5a8f4a7204a275c529e68cab2c7930929c64
1 /**
2 * @file
4 * This program checks if the compiler / platform supports the
5 * std::unique_ptr<> correctly. The motivation for this test was a discussion
6 * on the development mailing list, and the documentation was captured
7 * in:
9 * http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=3715
12 #include "test_config.h"
14 // The first part of the test is to compile this line. If the program
15 // does not compile the platform is just too broken.
16 #include <memory>
17 #include <utility>
19 // For extra challenge, we use the anonymous namespace
20 namespace
22 /**
23 * @class Base
25 class Base
27 public:
28 Base()
30 constructors++;
32 Base(Base const & )
34 constructors++;
36 ~Base()
38 destructors++;
41 static int constructors;
42 static int destructors;
45 int Base::constructors = 0;
46 int Base::destructors = 0;
48 class Derived : public Base
50 public:
51 Derived()
52 : Base()
57 int
58 run_main (int, ACE_TCHAR *[])
60 ACE_START_TEST (ACE_TEXT("Compiler_Features_09_Test"));
62 // As usual, the exit status from the test is 0 on success, 1 on
63 // failure
64 int status = 0;
66 // ... this works with the ACE version of unique_ptr (well, the
67 // namespace is broken, but you get the idea) ...
68 std::unique_ptr<Base> x(new Base);
69 std::unique_ptr<Derived> y(new Derived);
71 // ... with a compliant implementation of std::unique_ptr<> you should be
72 // able to write:
73 // x = y;
74 x.reset(y.release());
76 // ... there should be just one destruction so far ...
77 if (Base::destructors != 1)
79 status = 1;
80 ACE_ERROR((LM_ERROR,
81 ACE_TEXT("Destructor count off, expected 1, found %d\n"),
82 Base::destructors));
85 std::unique_ptr<Base> z;
86 z = std::move(x);
87 if (Base::destructors != 1)
89 status = 1;
90 ACE_ERROR((LM_ERROR,
91 ACE_TEXT("Destructor count off, expected 1, found %d\n"),
92 Base::destructors));
94 if (x.get())
96 status = 1;
97 ACE_ERROR((LM_ERROR,
98 ACE_TEXT("x contents should have been transferred\n")
99 ));
102 ACE_END_TEST;
103 return status;