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/libvrflinger/hardware_composer.cpp b/libs/vr/libvrflinger/hardware_composer.cpp
index b8d5e2b..64079e1 100644
--- a/libs/vr/libvrflinger/hardware_composer.cpp
+++ b/libs/vr/libvrflinger/hardware_composer.cpp
@@ -99,7 +99,7 @@
class TraceArgs {
public:
template <typename... Args>
- TraceArgs(const char* format, Args&&... args) {
+ explicit TraceArgs(const char* format, Args&&... args) {
std::array<char, 1024> buffer;
snprintf(buffer.data(), buffer.size(), format, std::forward<Args>(args)...);
atrace_begin(ATRACE_TAG, buffer.data());
diff --git a/libs/vr/libvrflinger/hardware_composer.h b/libs/vr/libvrflinger/hardware_composer.h
index 539a7fb..f1a755b 100644
--- a/libs/vr/libvrflinger/hardware_composer.h
+++ b/libs/vr/libvrflinger/hardware_composer.h
@@ -195,7 +195,7 @@
AcquiredBuffer acquired_buffer;
pdx::LocalHandle release_fence;
- SourceSurface(const std::shared_ptr<DirectDisplaySurface>& surface)
+ explicit SourceSurface(const std::shared_ptr<DirectDisplaySurface>& surface)
: surface(surface) {}
// Attempts to acquire a new buffer from the surface and return a tuple with
diff --git a/libs/vr/libvrflinger/hwc_types.h b/libs/vr/libvrflinger/hwc_types.h
index cbf636c..8b5c3b3 100644
--- a/libs/vr/libvrflinger/hwc_types.h
+++ b/libs/vr/libvrflinger/hwc_types.h
@@ -116,19 +116,24 @@
Wrapper(const Wrapper&) = default;
// Implicit conversion from ValueType.
+ // NOLINTNEXTLINE(google-explicit-constructor)
Wrapper(ValueType value) : value(value) {}
// Implicit conversion from BaseType.
+ // NOLINTNEXTLINE(google-explicit-constructor)
Wrapper(BaseType value) : value(static_cast<ValueType>(value)) {}
// Implicit conversion from an enum type of the same underlying type.
template <typename T, typename = EnableIfMatchingEnum<T, ValueType>>
+ // NOLINTNEXTLINE(google-explicit-constructor)
Wrapper(const T& value) : value(static_cast<ValueType>(value)) {}
// Implicit conversion to BaseType.
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator BaseType() const { return static_cast<BaseType>(value); }
// Implicit conversion to ValueType.
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator ValueType() const { return value; }
template <typename T, typename = EnableIfMatchingEnum<T, ValueType>>
@@ -275,8 +280,10 @@
struct Color final {
Color(const Color&) = default;
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : r(r), g(g), b(b), a(a) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
Color(hwc_color_t color) : r(color.r), g(color.g), b(color.b), a(color.a) {}
+ // NOLINTNEXTLINE(google-explicit-constructor)
operator hwc_color_t() const { return {r, g, b, a}; }
uint8_t r __attribute__((aligned(1)));
diff --git a/libs/vr/libvrflinger/include/dvr/vr_flinger.h b/libs/vr/libvrflinger/include/dvr/vr_flinger.h
index c740dde..ae52076 100644
--- a/libs/vr/libvrflinger/include/dvr/vr_flinger.h
+++ b/libs/vr/libvrflinger/include/dvr/vr_flinger.h
@@ -49,7 +49,8 @@
// Needs to be a separate class for binder's ref counting
class PersistentVrStateCallback : public BnPersistentVrStateCallbacks {
public:
- PersistentVrStateCallback(RequestDisplayCallback request_display_callback)
+ explicit PersistentVrStateCallback(
+ RequestDisplayCallback request_display_callback)
: request_display_callback_(request_display_callback) {}
void onPersistentVrStateChanged(bool enabled) override;
private: