From 52edc855b2b7ccb0816e7a08006dd7bf9891838c Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Thu, 3 Nov 2016 15:46:34 -0700 Subject: 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 --- runtime/obj_ptr.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/runtime/obj_ptr.h b/runtime/obj_ptr.h index 93182323d6..d24c6fbd2c 100644 --- a/runtime/obj_ptr.h +++ b/runtime/obj_ptr.h @@ -20,6 +20,7 @@ #include #include +#include "base/macros.h" #include "base/mutex.h" // For Locks::mutator_lock_. #include "globals.h" @@ -41,17 +42,26 @@ class ObjPtr { 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 - 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(ptr))) { static_assert(std::is_base_of::value, "Input type must be a subtype of the ObjPtr type"); } template - ALWAYS_INLINE ObjPtr(const ObjPtr& other) REQUIRES_SHARED(Locks::mutator_lock_) + ALWAYS_INLINE ObjPtr(const ObjPtr& other) // NOLINT + REQUIRES_SHARED(Locks::mutator_lock_) : reference_(Encode(static_cast(other.Ptr()))) { static_assert(std::is_base_of::value, "Input type must be a subtype of the ObjPtr type"); @@ -154,6 +164,9 @@ class ObjPtr { uintptr_t reference_; }; +static_assert(std::is_trivially_copyable>::value, + "ObjPtr should be trivially copyable"); + // Hash function for stl data structures. class HashObjPtr { public: -- cgit v1.2.3-59-g8ed1b