Fix google-explicit-constructor warnings in utils.
* Declare explicit conversion constructors.
* Use NOLINT(implicit) for implicit conversion constructors.
Bug: 28341362
Change-Id: I4fb58fa32aafc520b2ed862a05a8bdbfabbc6c35
Test: build with WITH_TIDY=1
diff --git a/include/utils/Condition.h b/include/utils/Condition.h
index a420185..5650598 100644
--- a/include/utils/Condition.h
+++ b/include/utils/Condition.h
@@ -54,7 +54,7 @@
};
Condition();
- Condition(int type);
+ explicit Condition(int type);
~Condition();
// Wait on the condition variable. Lock the mutex before calling.
status_t wait(Mutex& mutex);
diff --git a/include/utils/Mutex.h b/include/utils/Mutex.h
index f027c79..8b720b9 100644
--- a/include/utils/Mutex.h
+++ b/include/utils/Mutex.h
@@ -48,8 +48,8 @@
};
Mutex();
- Mutex(const char* name);
- Mutex(int type, const char* name = NULL);
+ explicit Mutex(const char* name);
+ explicit Mutex(int type, const char* name = NULL);
~Mutex();
// lock or unlock the mutex
@@ -73,8 +73,8 @@
// constructed and released when Autolock goes out of scope.
class Autolock {
public:
- inline Autolock(Mutex& mutex) : mLock(mutex) { mLock.lock(); }
- inline Autolock(Mutex* mutex) : mLock(*mutex) { mLock.lock(); }
+ inline explicit Autolock(Mutex& mutex) : mLock(mutex) { mLock.lock(); }
+ inline explicit Autolock(Mutex* mutex) : mLock(*mutex) { mLock.lock(); }
inline ~Autolock() { mLock.unlock(); }
private:
Mutex& mLock;
diff --git a/include/utils/RWLock.h b/include/utils/RWLock.h
index e743b1c..d5b81d3 100644
--- a/include/utils/RWLock.h
+++ b/include/utils/RWLock.h
@@ -47,8 +47,8 @@
};
RWLock();
- RWLock(const char* name);
- RWLock(int type, const char* name = NULL);
+ explicit RWLock(const char* name);
+ explicit RWLock(int type, const char* name = NULL);
~RWLock();
status_t readLock();
@@ -59,7 +59,7 @@
class AutoRLock {
public:
- inline AutoRLock(RWLock& rwlock) : mLock(rwlock) { mLock.readLock(); }
+ inline explicit AutoRLock(RWLock& rwlock) : mLock(rwlock) { mLock.readLock(); }
inline ~AutoRLock() { mLock.unlock(); }
private:
RWLock& mLock;
@@ -67,7 +67,7 @@
class AutoWLock {
public:
- inline AutoWLock(RWLock& rwlock) : mLock(rwlock) { mLock.writeLock(); }
+ inline explicit AutoWLock(RWLock& rwlock) : mLock(rwlock) { mLock.writeLock(); }
inline ~AutoWLock() { mLock.unlock(); }
private:
RWLock& mLock;
diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h
index c82e7d9..950dbd0 100644
--- a/include/utils/RefBase.h
+++ b/include/utils/RefBase.h
@@ -222,12 +222,12 @@
inline wp() : m_ptr(0) { }
- wp(T* other);
+ wp(T* other); // NOLINT(implicit)
wp(const wp<T>& other);
- wp(const sp<T>& other);
- template<typename U> wp(U* other);
- template<typename U> wp(const sp<U>& other);
- template<typename U> wp(const wp<U>& other);
+ explicit wp(const sp<T>& other);
+ template<typename U> wp(U* other); // NOLINT(implicit)
+ template<typename U> wp(const sp<U>& other); // NOLINT(implicit)
+ template<typename U> wp(const wp<U>& other); // NOLINT(implicit)
~wp();
diff --git a/include/utils/StrongPointer.h b/include/utils/StrongPointer.h
index 50fde35..d90b788 100644
--- a/include/utils/StrongPointer.h
+++ b/include/utils/StrongPointer.h
@@ -60,12 +60,12 @@
public:
inline sp() : m_ptr(0) { }
- sp(T* other);
+ sp(T* other); // NOLINT(implicit)
sp(const sp<T>& other);
sp(sp<T>&& other);
- template<typename U> sp(U* other);
- template<typename U> sp(const sp<U>& other);
- template<typename U> sp(sp<U>&& other);
+ template<typename U> sp(U* other); // NOLINT(implicit)
+ template<typename U> sp(const sp<U>& other); // NOLINT(implicit)
+ template<typename U> sp(sp<U>&& other); // NOLINT(implicit)
~sp();
diff --git a/include/utils/Thread.h b/include/utils/Thread.h
index 1532b7e..0f7ac9f 100644
--- a/include/utils/Thread.h
+++ b/include/utils/Thread.h
@@ -41,7 +41,7 @@
public:
// Create a Thread object, but doesn't create or start the associated
// thread. See the run() method.
- Thread(bool canCallJava = true);
+ explicit Thread(bool canCallJava = true);
virtual ~Thread();
// Start the thread in threadLoop() which needs to be implemented.
diff --git a/include/utils/TypeHelpers.h b/include/utils/TypeHelpers.h
index 61d618e..64d25c5 100644
--- a/include/utils/TypeHelpers.h
+++ b/include/utils/TypeHelpers.h
@@ -240,7 +240,7 @@
key_value_pair_t() { }
key_value_pair_t(const key_value_pair_t& o) : key(o.key), value(o.value) { }
key_value_pair_t(const KEY& k, const VALUE& v) : key(k), value(v) { }
- key_value_pair_t(const KEY& k) : key(k) { }
+ explicit key_value_pair_t(const KEY& k) : key(k) { }
inline bool operator < (const key_value_pair_t& o) const {
return strictly_order_type(key, o.key);
}
diff --git a/include/utils/VectorImpl.h b/include/utils/VectorImpl.h
index 21ad71c..4dd91fd 100644
--- a/include/utils/VectorImpl.h
+++ b/include/utils/VectorImpl.h
@@ -132,7 +132,7 @@
{
public:
SortedVectorImpl(size_t itemSize, uint32_t flags);
- SortedVectorImpl(const VectorImpl& rhs);
+ explicit SortedVectorImpl(const VectorImpl& rhs);
virtual ~SortedVectorImpl();
SortedVectorImpl& operator = (const SortedVectorImpl& rhs);