Bug 1316206 - Make RefPtr(decltype(nullptr)) MOZ_IMPLICIT - r=froydnj
Making this constructor non-explicit will permit automatic conversions from
'nullptr' into RefPtr types, which I think are not dangerous.
The one spot that this affects is in 'UserDataType nsBaseHashtable::Get(KeyType)',
which does a 'return 0;' into the UserDataType, which could be a bool, an int, a
RefPtr or other. I'm changing that into a C++11 "value initialization", which
falls back to "zero initialization" for PODs: 'return UserDataType{};'.
Also fixed the comment to clarify not-found return values, as Get(KeyType) was
not only used for pointers anyway.
MozReview-Commit-ID: F41VlvTNOZU
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -107,17 +107,17 @@ public:
MOZ_IMPLICIT RefPtr(T* aRawPtr)
: mRawPtr(aRawPtr)
{
if (mRawPtr) {
ConstRemovingRefPtrTraits<T>::AddRef(mRawPtr);
}
}
- explicit RefPtr(decltype(nullptr))
+ MOZ_IMPLICIT RefPtr(decltype(nullptr))
: mRawPtr(nullptr)
{
}
template <typename I>
MOZ_IMPLICIT RefPtr(already_AddRefed<I>& aSmartPtr)
: mRawPtr(aSmartPtr.take())
// construct from |already_AddRefed|
--- a/xpcom/glue/nsBaseHashtable.h
+++ b/xpcom/glue/nsBaseHashtable.h
@@ -91,29 +91,30 @@ public:
if (aData) {
*aData = ent->mData;
}
return true;
}
/**
- * For pointer types, get the value, returning nullptr if the entry is not
- * present in the table.
+ * Get the value, returning a zero-initialized POD or a default-initialized
+ * object if the entry is not present in the table.
*
* @param aKey the key to retrieve
- * @return The found value, or nullptr if no entry was found with the given key.
- * @note If nullptr values are stored in the table, it is not possible to
- * distinguish between a nullptr value and a missing entry.
+ * @return The found value, or UserDataType{} if no entry was found with the
+ * given key.
+ * @note If zero/default-initialized values are stored in the table, it is
+ * not possible to distinguish between such a value and a missing entry.
*/
UserDataType Get(KeyType aKey) const
{
EntryType* ent = this->GetEntry(aKey);
if (!ent) {
- return 0;
+ return UserDataType{};
}
return ent->mData;
}
/**
* put a new value for the associated key
* @param aKey the key to put