[llvm] r194317 - Add the critically missing 'clone' method. =]
Chandler Carruth
chandlerc at gmail.com
Fri Nov 8 20:32:34 PST 2013
Author: chandlerc
Date: Fri Nov 8 22:32:34 2013
New Revision: 194317
URL: http://llvm.org/viewvc/llvm-project?rev=194317&view=rev
Log:
Add the critically missing 'clone' method. =]
Clang managed to never instantiate the copy constructor. Added tests to
ensure this path is tested.
We could still use tests for the polymorphic nature. Those coming up
next.
Modified:
llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp
Modified: llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp?rev=194317&r1=194316&r2=194317&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp (original)
+++ llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp Fri Nov 8 22:32:34 2013
@@ -17,9 +17,13 @@ namespace {
struct S {
S(int x) : x(x) {}
+ S *clone() { return new S(*this); }
int x;
};
+// A function that forces the return of a copy.
+polymorphic_ptr<S> dummy_copy(const polymorphic_ptr<S> &arg) { return arg; }
+
TEST(polymorphic_ptr_test, Basic) {
polymorphic_ptr<S> null;
EXPECT_FALSE((bool)null);
@@ -66,6 +70,13 @@ TEST(polymorphic_ptr_test, Basic) {
EXPECT_EQ(s, &*p);
EXPECT_FALSE((bool)p2);
EXPECT_TRUE(!p2);
+
+ // Force copies and that everything survives.
+ polymorphic_ptr<S> p3 = dummy_copy(polymorphic_ptr<S>(p));
+ EXPECT_TRUE((bool)p3);
+ EXPECT_FALSE(!p3);
+ EXPECT_NE(s, &*p3);
+ EXPECT_EQ(42, p3->x);
}
}
More information about the llvm-commits
mailing list