From 1811d156e9c6b5486d25090ec3e911632dc6edff Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 26 Sep 2016 14:24:48 -0700 Subject: [PATCH] Fix more system/core/include warnings The warnings in these files were hidden by -isystem framework/native/include. Bug: 31752268 Test: m -j Change-Id: I2a54376aea380ee24e6483fb7d35fdfe8991c490 --- include/cutils/native_handle.h | 7 +++++++ include/utils/Flattenable.h | 16 ++++++++-------- include/utils/KeyedVector.h | 2 +- include/utils/RefBase.h | 14 +++++++++++++- include/utils/TypeHelpers.h | 25 +++++++++++++++---------- include/utils/Vector.h | 2 +- libutils/RefBase.cpp | 2 -- 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h index 268c5d3f5..31695cb48 100644 --- a/include/cutils/native_handle.h +++ b/include/cutils/native_handle.h @@ -26,7 +26,14 @@ typedef struct native_handle int version; /* sizeof(native_handle_t) */ int numFds; /* number of file-descriptors at &data[0] */ int numInts; /* number of ints at &data[numFds] */ +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wzero-length-array" +#endif int data[0]; /* numFds + numInts ints */ +#if defined(__clang__) +#pragma clang diagnostic pop +#endif } native_handle_t; /* diff --git a/include/utils/Flattenable.h b/include/utils/Flattenable.h index c37ac60c7..22b811a14 100644 --- a/include/utils/Flattenable.h +++ b/include/utils/Flattenable.h @@ -31,32 +31,32 @@ namespace android { class FlattenableUtils { public: - template + template static size_t align(size_t size) { COMPILE_TIME_ASSERT_FUNCTION_SCOPE( !(N & (N-1)) ); return (size + (N-1)) & ~(N-1); } - template + template static size_t align(void const*& buffer) { COMPILE_TIME_ASSERT_FUNCTION_SCOPE( !(N & (N-1)) ); - intptr_t b = intptr_t(buffer); - buffer = (void*)((intptr_t(buffer) + (N-1)) & ~(N-1)); - return size_t(intptr_t(buffer) - b); + uintptr_t b = uintptr_t(buffer); + buffer = reinterpret_cast((uintptr_t(buffer) + (N-1)) & ~(N-1)); + return size_t(uintptr_t(buffer) - b); } - template + template static size_t align(void*& buffer) { return align( const_cast(buffer) ); } static void advance(void*& buffer, size_t& size, size_t offset) { - buffer = reinterpret_cast( intptr_t(buffer) + offset ); + buffer = reinterpret_cast( uintptr_t(buffer) + offset ); size -= offset; } static void advance(void const*& buffer, size_t& size, size_t offset) { - buffer = reinterpret_cast( intptr_t(buffer) + offset ); + buffer = reinterpret_cast( uintptr_t(buffer) + offset ); size -= offset; } diff --git a/include/utils/KeyedVector.h b/include/utils/KeyedVector.h index e3d19e1e8..92579e25f 100644 --- a/include/utils/KeyedVector.h +++ b/include/utils/KeyedVector.h @@ -157,7 +157,7 @@ template inline VALUE& KeyedVector::editValueFor(const KEY& key) { ssize_t i = this->indexOfKey(key); LOG_ALWAYS_FATAL_IF(i<0, "%s: key not found", __PRETTY_FUNCTION__); - return mVector.editItemAt(i).value; + return mVector.editItemAt(static_cast(i)).value; } template inline diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h index c6466d3f3..36016cde6 100644 --- a/include/utils/RefBase.h +++ b/include/utils/RefBase.h @@ -206,17 +206,29 @@ inline bool operator _op_ (const U* o) const { \ // --------------------------------------------------------------------------- +// RefererenceRenamer is pure abstract, there is no virtual method +// implementation to put in a translation unit in order to silence the +// weak vtables warning. +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#endif + class ReferenceRenamer { protected: // destructor is purposedly not virtual so we avoid code overhead from // subclasses; we have to make it protected to guarantee that it // cannot be called from this base class (and to make strict compilers // happy). - ~ReferenceRenamer(); + ~ReferenceRenamer() { } public: virtual void operator()(size_t i) const = 0; }; +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + // --------------------------------------------------------------------------- class RefBase diff --git a/include/utils/TypeHelpers.h b/include/utils/TypeHelpers.h index 627579350..2a2522722 100644 --- a/include/utils/TypeHelpers.h +++ b/include/utils/TypeHelpers.h @@ -151,16 +151,21 @@ void destroy_type(TYPE* p, size_t n) { } } -template inline -void copy_type(TYPE* d, const TYPE* s, size_t n) { - if (!traits::has_trivial_copy) { - while (n > 0) { - n--; - new(d) TYPE(*s); - d++, s++; - } - } else { - memcpy(d,s,n*sizeof(TYPE)); +template +typename std::enable_if::has_trivial_copy>::type +inline +copy_type(TYPE* d, const TYPE* s, size_t n) { + memcpy(d,s,n*sizeof(TYPE)); +} + +template +typename std::enable_if::has_trivial_copy>::type +inline +copy_type(TYPE* d, const TYPE* s, size_t n) { + while (n > 0) { + n--; + new(d) TYPE(*s); + d++, s++; } } diff --git a/include/utils/Vector.h b/include/utils/Vector.h index 81ac9c7a1..b6d5686ac 100644 --- a/include/utils/Vector.h +++ b/include/utils/Vector.h @@ -194,7 +194,7 @@ public: inline void push_back(const TYPE& item) { insertAt(item, size(), 1); } inline void push_front(const TYPE& item) { insertAt(item, 0, 1); } inline iterator erase(iterator pos) { - ssize_t index = removeItemsAt(pos-array()); + ssize_t index = removeItemsAt(static_cast(pos-array())); return begin() + index; } diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index ba1aaee39..1f8395b40 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -770,8 +770,6 @@ void RefBase::renameRefId(RefBase* ref, ref->mRefs->renameWeakRefId(old_id, new_id); } -ReferenceRenamer::~ReferenceRenamer() {} - VirtualLightRefBase::~VirtualLightRefBase() {} }; // namespace android