Remove the explicit keyword from the ScopedComPtr constructor so it can be included in a STL container.
Review URL: http://codereview.chromium.org/115247
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15958 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/scoped_comptr_win.h b/base/scoped_comptr_win.h
index 9ba0b849..3fa419f 100644
--- a/base/scoped_comptr_win.h
+++ b/base/scoped_comptr_win.h
@@ -34,7 +34,7 @@
explicit ScopedComPtr(Interface* p) : ParentClass(p) {
}
- explicit ScopedComPtr(const ScopedComPtr<Interface, interface_id>& p)
+ ScopedComPtr(const ScopedComPtr<Interface, interface_id>& p)
: ParentClass(p) {
}
diff --git a/base/scoped_comptr_win_unittest.cc b/base/scoped_comptr_win_unittest.cc
index 5e4ad3d310..e6d6c68 100644
--- a/base/scoped_comptr_win_unittest.cc
+++ b/base/scoped_comptr_win_unittest.cc
@@ -5,8 +5,26 @@
#include <shlobj.h>
#include "base/scoped_comptr_win.h"
+#include "base/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
+struct Dummy {
+ Dummy() : adds(0), releases(0) { }
+ void AddRef() { ++adds; }
+ void Release() { ++releases; }
+
+ int adds;
+ int releases;
+};
+
+extern const IID dummy_iid;
+const IID dummy_iid = { 0x12345678u, 0x1234u, 0x5678u, 01, 23, 45, 67, 89,
+ 01, 23, 45 };
+
+} // namespace
+
TEST(ScopedComPtrTest, ScopedComPtr) {
EXPECT_TRUE(memcmp(&ScopedComPtr<IUnknown>::iid(), &IID_IUnknown,
sizeof(IID)) == 0);
@@ -50,3 +68,30 @@
::CoUninitialize();
}
+
+TEST(ScopedComPtrTest, ScopedComPtrVector) {
+ // Verify we don't get error C2558.
+ typedef ScopedComPtr<Dummy, &dummy_iid> Ptr;
+ std::vector<Ptr> bleh;
+ scoped_ptr<Dummy> p(new Dummy);
+ {
+ Ptr p2(p.get());
+ EXPECT_EQ(p->adds, 1);
+ EXPECT_EQ(p->releases, 0);
+ Ptr p3 = p2;
+ EXPECT_EQ(p->adds, 2);
+ EXPECT_EQ(p->releases, 0);
+ p3 = p2;
+ EXPECT_EQ(p->adds, 3);
+ EXPECT_EQ(p->releases, 1);
+ bleh.push_back(p2);
+ EXPECT_EQ(p->adds, 5);
+ EXPECT_EQ(p->releases, 2);
+ EXPECT_EQ(bleh[0], p.get());
+ bleh.pop_back();
+ EXPECT_EQ(p->adds, 5);
+ EXPECT_EQ(p->releases, 3);
+ }
+ EXPECT_EQ(p->adds, 5);
+ EXPECT_EQ(p->releases, 5);
+}