Fix/suppress libs/vr google-explicit-constructor warnings
* Add explicit to conversion constructors/operators
* Use NOLINT or NOLINTNEXTLINE to suppress warnings on intended converters
Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: I3631041531e3fb5cbcee246a7e7bb94fb06aa60b
diff --git a/libs/vr/libpdx/private/pdx/channel_handle.h b/libs/vr/libpdx/private/pdx/channel_handle.h
index daa08f4..bd04305 100644
--- a/libs/vr/libpdx/private/pdx/channel_handle.h
+++ b/libs/vr/libpdx/private/pdx/channel_handle.h
@@ -26,7 +26,7 @@
class ChannelHandleBase {
public:
ChannelHandleBase() = default;
- ChannelHandleBase(const int32_t& value) : value_{value} {}
+ explicit ChannelHandleBase(const int32_t& value) : value_{value} {}
ChannelHandleBase(const ChannelHandleBase&) = delete;
ChannelHandleBase& operator=(const ChannelHandleBase&) = delete;
diff --git a/libs/vr/libpdx/private/pdx/client.h b/libs/vr/libpdx/private/pdx/client.h
index c35dabd..7e2d55c 100644
--- a/libs/vr/libpdx/private/pdx/client.h
+++ b/libs/vr/libpdx/private/pdx/client.h
@@ -206,7 +206,7 @@
class Transaction final : public OutputResourceMapper,
public InputResourceMapper {
public:
- Transaction(Client& client);
+ explicit Transaction(Client& client);
~Transaction();
template <typename T>
diff --git a/libs/vr/libpdx/private/pdx/rpc/buffer_wrapper.h b/libs/vr/libpdx/private/pdx/rpc/buffer_wrapper.h
index 0421220..43184dd 100644
--- a/libs/vr/libpdx/private/pdx/rpc/buffer_wrapper.h
+++ b/libs/vr/libpdx/private/pdx/rpc/buffer_wrapper.h
@@ -110,10 +110,10 @@
using const_iterator = typename BufferType::const_iterator;
BufferWrapper() {}
- BufferWrapper(const BufferType& buffer) : buffer_(buffer) {}
+ explicit BufferWrapper(const BufferType& buffer) : buffer_(buffer) {}
BufferWrapper(const BufferType& buffer, const Allocator& allocator)
: buffer_(buffer, allocator) {}
- BufferWrapper(BufferType&& buffer) : buffer_(std::move(buffer)) {}
+ explicit BufferWrapper(BufferType&& buffer) : buffer_(std::move(buffer)) {}
BufferWrapper(BufferType&& buffer, const Allocator& allocator)
: buffer_(std::move(buffer), allocator) {}
BufferWrapper(const BufferWrapper&) = default;
diff --git a/libs/vr/libpdx/private/pdx/rpc/payload.h b/libs/vr/libpdx/private/pdx/rpc/payload.h
index a48a64c..d2df14f 100644
--- a/libs/vr/libpdx/private/pdx/rpc/payload.h
+++ b/libs/vr/libpdx/private/pdx/rpc/payload.h
@@ -83,7 +83,7 @@
public MessageWriter,
public MessageReader {
public:
- ServicePayload(Message& message) : message_(message) {}
+ explicit ServicePayload(Message& message) : message_(message) {}
// MessageWriter
void* GetNextWriteBufferSection(size_t size) override {
@@ -120,7 +120,8 @@
MessageBuffer<ThreadLocalTypeSlot<ClientPayload<Slot>>, 1024u, int>;
using BufferType = typename ContainerType::BufferType;
- ClientPayload(Transaction& transaction) : transaction_{transaction} {}
+ explicit ClientPayload(Transaction& transaction)
+ : transaction_{transaction} {}
// MessageWriter
void* GetNextWriteBufferSection(size_t size) override {
diff --git a/libs/vr/libpdx/private/pdx/rpc/pointer_wrapper.h b/libs/vr/libpdx/private/pdx/rpc/pointer_wrapper.h
index 1cb85de..88868fe 100644
--- a/libs/vr/libpdx/private/pdx/rpc/pointer_wrapper.h
+++ b/libs/vr/libpdx/private/pdx/rpc/pointer_wrapper.h
@@ -13,7 +13,7 @@
public:
using BaseType = T;
- PointerWrapper(T* pointer) : pointer_(pointer) {}
+ explicit PointerWrapper(T* pointer) : pointer_(pointer) {}
PointerWrapper(const PointerWrapper&) = default;
PointerWrapper(PointerWrapper&&) noexcept = default;
PointerWrapper& operator=(const PointerWrapper&) = default;
diff --git a/libs/vr/libpdx/private/pdx/rpc/serialization.h b/libs/vr/libpdx/private/pdx/rpc/serialization.h
index f12aef1..914ea66 100644
--- a/libs/vr/libpdx/private/pdx/rpc/serialization.h
+++ b/libs/vr/libpdx/private/pdx/rpc/serialization.h
@@ -134,7 +134,7 @@
// ErrorType constructor for generic error codes. Explicitly not explicit,
// implicit conversion from ErrorCode to ErrorType is desirable behavior.
- // NOLINTNEXTLINE(runtime/explicit)
+ // NOLINTNEXTLINE(google-explicit-constructor)
ErrorType(ErrorCode error_code) : error_code_(error_code) {}
// ErrorType constructor for encoding type errors.
@@ -148,6 +148,7 @@
// Evaluates to true if the ErrorType represents an error.
explicit operator bool() const { return error_code_ != ErrorCode::NO_ERROR; }
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator ErrorCode() const { return error_code_; }
ErrorCode error_code() const { return error_code_; }
@@ -159,6 +160,7 @@
return unexpected_encoding_.encoding_type;
}
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator std::string() const {
std::ostringstream stream;
diff --git a/libs/vr/libpdx/private/pdx/service.h b/libs/vr/libpdx/private/pdx/service.h
index 234b24a..853d53c 100644
--- a/libs/vr/libpdx/private/pdx/service.h
+++ b/libs/vr/libpdx/private/pdx/service.h
@@ -86,7 +86,7 @@
class Message : public OutputResourceMapper, public InputResourceMapper {
public:
Message();
- Message(const MessageInfo& info);
+ explicit Message(const MessageInfo& info);
~Message();
/*
diff --git a/libs/vr/libpdx/private/pdx/status.h b/libs/vr/libpdx/private/pdx/status.h
index 7e51a52..498dd6d 100644
--- a/libs/vr/libpdx/private/pdx/status.h
+++ b/libs/vr/libpdx/private/pdx/status.h
@@ -11,6 +11,7 @@
// This is a helper class for constructing Status<T> with an error code.
struct ErrorStatus {
public:
+ // NOLINTNEXTLINE(google-explicit-constructor)
ErrorStatus(int error) : error_{error} {}
int error() const { return error_; }
@@ -31,12 +32,14 @@
// Value copy/move constructors. These are intentionally not marked as
// explicit to allow direct value returns from functions without having
// to explicitly wrap them into Status<T>().
- Status(const T& value) : value_{value} {} // NOLINT(runtime/explicit)
- Status(T&& value) : value_{std::move(value)} {} // NOLINT(runtime/explicit)
+ // NOLINTNEXTLINE(google-explicit-constructor)
+ Status(const T& value) : value_{value} {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
+ Status(T&& value) : value_{std::move(value)} {}
// Constructor for storing an error code inside the Status object.
- Status(const ErrorStatus& error_status) // NOLINT(runtime/explicit)
- : error_{error_status.error()} {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
+ Status(const ErrorStatus& error_status) : error_{error_status.error()} {}
// Copy/move constructors. Move constructor leaves |other| object in empty
// state.
@@ -135,8 +138,8 @@
class Status<void> {
public:
Status() = default;
- Status(const ErrorStatus& error_status) // NOLINT(runtime/explicit)
- : error_{error_status.error()} {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
+ Status(const ErrorStatus& error_status) : error_{error_status.error()} {}
void SetValue() { error_ = 0; }
void SetError(int error) { error_ = error; }
diff --git a/libs/vr/libpdx/serialization_tests.cpp b/libs/vr/libpdx/serialization_tests.cpp
index 5ad1047..ee800f6 100644
--- a/libs/vr/libpdx/serialization_tests.cpp
+++ b/libs/vr/libpdx/serialization_tests.cpp
@@ -70,7 +70,7 @@
FileHandleType fd;
TestTemplateType() {}
- TestTemplateType(FileHandleType fd) : fd(std::move(fd)) {}
+ explicit TestTemplateType(FileHandleType fd) : fd(std::move(fd)) {}
bool operator==(const TestTemplateType& other) const {
return fd.Get() == other.fd.Get();
diff --git a/libs/vr/libpdx/variant_tests.cpp b/libs/vr/libpdx/variant_tests.cpp
index e3520f5..a977fd3 100644
--- a/libs/vr/libpdx/variant_tests.cpp
+++ b/libs/vr/libpdx/variant_tests.cpp
@@ -14,18 +14,22 @@
namespace {
struct BaseType {
+ // NOLINTNEXTLINE(google-explicit-constructor)
BaseType(int value) : value(value) {}
int value;
};
struct DerivedType : BaseType {
+ // NOLINTNEXTLINE(google-explicit-constructor)
DerivedType(int value) : BaseType{value} {};
};
template <typename T>
class TestType {
public:
+ // NOLINTNEXTLINE(google-explicit-constructor)
TestType(const T& value) : value_(value) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
TestType(T&& value) : value_(std::move(value)) {}
TestType(const TestType&) = default;
TestType(TestType&&) = default;
@@ -43,7 +47,9 @@
template <typename T>
class InstrumentType {
public:
+ // NOLINTNEXTLINE(google-explicit-constructor)
InstrumentType(const T& value) : value_(value) { constructor_count_++; }
+ // NOLINTNEXTLINE(google-explicit-constructor)
InstrumentType(T&& value) : value_(std::move(value)) { constructor_count_++; }
InstrumentType(const InstrumentType& other) : value_(other.value_) {
constructor_count_++;
@@ -51,9 +57,11 @@
InstrumentType(InstrumentType&& other) : value_(std::move(other.value_)) {
constructor_count_++;
}
+ // NOLINTNEXTLINE(google-explicit-constructor)
InstrumentType(const TestType<T>& other) : value_(other.get()) {
constructor_count_++;
}
+ // NOLINTNEXTLINE(google-explicit-constructor)
InstrumentType(TestType<T>&& other) : value_(other.take()) {
constructor_count_++;
}
@@ -1101,6 +1109,7 @@
TEST(Variant, IsConstructible) {
using ArrayType = const float[3];
struct ImplicitBool {
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator bool() const { return true; }
};
struct ExplicitBool {