ART: Add NOLINT to ObjPtr
The ObjPtr constructors are constructed to allow implicit conversion.
Also ensure that ObjPtr is trivially copyable.
Bug: 32619234
Test: m
Change-Id: I022e8d7d5a54c0057e9007bb7c13312b343c23b6
diff --git a/runtime/obj_ptr.h b/runtime/obj_ptr.h
index 9318232..d24c6fb 100644
--- a/runtime/obj_ptr.h
+++ b/runtime/obj_ptr.h
@@ -20,6 +20,7 @@
#include <ostream>
#include <type_traits>
+#include "base/macros.h"
#include "base/mutex.h" // For Locks::mutator_lock_.
#include "globals.h"
@@ -41,17 +42,26 @@
public:
ALWAYS_INLINE ObjPtr() REQUIRES_SHARED(Locks::mutator_lock_) : reference_(0u) {}
- ALWAYS_INLINE ObjPtr(std::nullptr_t) REQUIRES_SHARED(Locks::mutator_lock_) : reference_(0u) {}
+ // Note: The following constructors allow implicit conversion. This simplifies code that uses
+ // them, e.g., for parameter passing. However, in general, implicit-conversion constructors
+ // are discouraged and detected by cpplint and clang-tidy. So mark these constructors
+ // as NOLINT (without category, as the categories are different).
+
+ ALWAYS_INLINE ObjPtr(std::nullptr_t) // NOLINT
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ : reference_(0u) {}
template <typename Type>
- ALWAYS_INLINE ObjPtr(Type* ptr) REQUIRES_SHARED(Locks::mutator_lock_)
+ ALWAYS_INLINE ObjPtr(Type* ptr) // NOLINT
+ REQUIRES_SHARED(Locks::mutator_lock_)
: reference_(Encode(static_cast<MirrorType*>(ptr))) {
static_assert(std::is_base_of<MirrorType, Type>::value,
"Input type must be a subtype of the ObjPtr type");
}
template <typename Type>
- ALWAYS_INLINE ObjPtr(const ObjPtr<Type, kPoison>& other) REQUIRES_SHARED(Locks::mutator_lock_)
+ ALWAYS_INLINE ObjPtr(const ObjPtr<Type, kPoison>& other) // NOLINT
+ REQUIRES_SHARED(Locks::mutator_lock_)
: reference_(Encode(static_cast<MirrorType*>(other.Ptr()))) {
static_assert(std::is_base_of<MirrorType, Type>::value,
"Input type must be a subtype of the ObjPtr type");
@@ -154,6 +164,9 @@
uintptr_t reference_;
};
+static_assert(std::is_trivially_copyable<ObjPtr<void>>::value,
+ "ObjPtr should be trivially copyable");
+
// Hash function for stl data structures.
class HashObjPtr {
public: