diff --git a/rtc_base/ref_counted_object.h b/rtc_base/ref_counted_object.h index 5298f06511..331132c569 100644 --- a/rtc_base/ref_counted_object.h +++ b/rtc_base/ref_counted_object.h @@ -64,21 +64,14 @@ template class FinalRefCountedObject final : public T { public: using T::T; - // Until c++17 compilers are allowed not to inherit the default constructor, - // and msvc doesn't. Thus the default constructor is forwarded explicitly. + // Until c++17 compilers are allowed not to inherit the default constructors. + // Thus the default constructors are forwarded explicitly. FinalRefCountedObject() = default; + explicit FinalRefCountedObject(const T& other) : T(other) {} + explicit FinalRefCountedObject(T&& other) : T(std::move(other)) {} FinalRefCountedObject(const FinalRefCountedObject&) = delete; FinalRefCountedObject& operator=(const FinalRefCountedObject&) = delete; - template - explicit FinalRefCountedObject(P0&& p0) : T(std::forward(p0)) {} - - template - FinalRefCountedObject(P0&& p0, P1&& p1, Args&&... args) - : T(std::forward(p0), - std::forward(p1), - std::forward(args)...) {} - void AddRef() const { ref_count_.IncRef(); } void Release() const { if (ref_count_.DecRef() == RefCountReleaseStatus::kDroppedLastRef) { diff --git a/rtc_base/ref_counted_object_unittest.cc b/rtc_base/ref_counted_object_unittest.cc index eeb93bea98..ab7bb09191 100644 --- a/rtc_base/ref_counted_object_unittest.cc +++ b/rtc_base/ref_counted_object_unittest.cc @@ -125,6 +125,22 @@ TEST(FinalRefCountedObject, CanWrapIntoScopedRefptr) { EXPECT_TRUE(ref2->HasOneRef()); } +TEST(FinalRefCountedObject, CanCreateFromMovedType) { + class MoveOnly { + public: + MoveOnly(int a) : a_(a) {} + MoveOnly(MoveOnly&&) = default; + + int a() { return a_; } + + private: + int a_; + }; + MoveOnly foo(5); + auto ref = make_ref_counted(std::move(foo)); + EXPECT_EQ(ref->a(), 5); +} + // This test is mostly a compile-time test for scoped_refptr compatibility. TEST(RefCounted, SmartPointers) { // Sanity compile-time tests. FooItf is virtual, Foo is not, FooItf inherits