[llvm] r194321 - Switch to allow implicit construction. In many cases, we're wrapping
Chandler Carruth
chandlerc at gmail.com
Fri Nov 8 21:55:04 PST 2013
Author: chandlerc
Date: Fri Nov 8 23:55:03 2013
New Revision: 194321
URL: http://llvm.org/viewvc/llvm-project?rev=194321&view=rev
Log:
Switch to allow implicit construction. In many cases, we're wrapping
a derived type and this makes it *much* easier to write this code.
Modified:
llvm/trunk/include/llvm/ADT/polymorphic_ptr.h
llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp
Modified: llvm/trunk/include/llvm/ADT/polymorphic_ptr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/polymorphic_ptr.h?rev=194321&r1=194320&r2=194321&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/polymorphic_ptr.h (original)
+++ llvm/trunk/include/llvm/ADT/polymorphic_ptr.h Fri Nov 8 23:55:03 2013
@@ -38,7 +38,7 @@ template <typename T> class polymorphic_
T *ptr;
public:
- explicit polymorphic_ptr(T *ptr = 0) : ptr(ptr) {}
+ polymorphic_ptr(T *ptr = 0) : ptr(ptr) {}
polymorphic_ptr(const polymorphic_ptr &arg) : ptr(arg->clone()) {}
#if LLVM_HAS_RVALUE_REFERENCES
polymorphic_ptr(polymorphic_ptr &&arg) : ptr(arg.take()) {}
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=194321&r1=194320&r2=194321&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp (original)
+++ llvm/trunk/unittests/ADT/polymorphic_ptr_test.cpp Fri Nov 8 23:55:03 2013
@@ -113,6 +113,11 @@ TEST(polymorphic_ptr_test, Polymorphism)
copy = dummy_copy(b);
EXPECT_NE(b, copy);
EXPECT_EQ("DerivedB", copy->name());
+
+ // Test creating a copy out of a temporary directly.
+ copy = dummy_copy<polymorphic_ptr<Base> >(new DerivedA());
+ EXPECT_NE(a, copy);
+ EXPECT_EQ("DerivedA", copy->name());
}
}
More information about the llvm-commits
mailing list