diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-11-09 04:32:34 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-11-09 04:32:34 +0000 |
commit | ca020d469e2a04f6805667c49a6b36f90a1856d2 (patch) | |
tree | ead48702fb0e6c3655a5cdd5a99806b1cff83a77 /unittests | |
parent | cd7a191d8aaf4869b0c53ddb04acba924424f2c8 (diff) | |
download | external_llvm-ca020d469e2a04f6805667c49a6b36f90a1856d2.zip external_llvm-ca020d469e2a04f6805667c49a6b36f90a1856d2.tar.gz external_llvm-ca020d469e2a04f6805667c49a6b36f90a1856d2.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194317 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/polymorphic_ptr_test.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/unittests/ADT/polymorphic_ptr_test.cpp b/unittests/ADT/polymorphic_ptr_test.cpp index 3606698..90c3385 100644 --- a/unittests/ADT/polymorphic_ptr_test.cpp +++ b/unittests/ADT/polymorphic_ptr_test.cpp @@ -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); } } |