From 45e31c739f6aaeec2c280eb098a44c69decebae2 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Thu, 20 Dec 2018 15:47:01 -0800 Subject: [PATCH] Fix/suppress cmds/lshal 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: I67a59b0051b5550ea135a91664bf03995e94eb75 --- cmds/lshal/Command.h | 2 +- cmds/lshal/DebugCommand.h | 2 +- cmds/lshal/HelpCommand.h | 2 +- cmds/lshal/ListCommand.h | 2 +- cmds/lshal/NullableOStream.h | 6 +++--- cmds/lshal/TableEntry.h | 2 +- cmds/lshal/TextTable.h | 6 +++--- cmds/lshal/Timeout.h | 2 +- cmds/lshal/test.cpp | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmds/lshal/Command.h b/cmds/lshal/Command.h index 4f128ab56b..e19e3f7fc2 100644 --- a/cmds/lshal/Command.h +++ b/cmds/lshal/Command.h @@ -27,7 +27,7 @@ class Lshal; // Base class for all *Commands class Command { public: - Command(Lshal& lshal) : mLshal(lshal) {} + explicit Command(Lshal& lshal) : mLshal(lshal) {} virtual ~Command() = default; // Expect optind to be set by Lshal::main and points to the next argument // to process. diff --git a/cmds/lshal/DebugCommand.h b/cmds/lshal/DebugCommand.h index 6e12008c8e..3c3f56fde5 100644 --- a/cmds/lshal/DebugCommand.h +++ b/cmds/lshal/DebugCommand.h @@ -31,7 +31,7 @@ class Lshal; class DebugCommand : public Command { public: - DebugCommand(Lshal &lshal) : Command(lshal) {} + explicit DebugCommand(Lshal &lshal) : Command(lshal) {} ~DebugCommand() = default; Status main(const Arg &arg) override; void usage() const override; diff --git a/cmds/lshal/HelpCommand.h b/cmds/lshal/HelpCommand.h index cc709f8ee4..da0cba6f42 100644 --- a/cmds/lshal/HelpCommand.h +++ b/cmds/lshal/HelpCommand.h @@ -31,7 +31,7 @@ class Lshal; class HelpCommand : public Command { public: - HelpCommand(Lshal &lshal) : Command(lshal) {} + explicit HelpCommand(Lshal &lshal) : Command(lshal) {} ~HelpCommand() = default; Status main(const Arg &arg) override; void usage() const override; diff --git a/cmds/lshal/ListCommand.h b/cmds/lshal/ListCommand.h index 3f7321d681..85195fcc54 100644 --- a/cmds/lshal/ListCommand.h +++ b/cmds/lshal/ListCommand.h @@ -57,7 +57,7 @@ enum class HalType { class ListCommand : public Command { public: - ListCommand(Lshal &lshal) : Command(lshal) {} + explicit ListCommand(Lshal &lshal) : Command(lshal) {} virtual ~ListCommand() = default; Status main(const Arg &arg) override; void usage() const override; diff --git a/cmds/lshal/NullableOStream.h b/cmds/lshal/NullableOStream.h index ab37a04c56..737d3a2963 100644 --- a/cmds/lshal/NullableOStream.h +++ b/cmds/lshal/NullableOStream.h @@ -25,8 +25,8 @@ namespace lshal { template class NullableOStream { public: - NullableOStream(S &os) : mOs(&os) {} - NullableOStream(S *os) : mOs(os) {} + explicit NullableOStream(S &os) : mOs(&os) {} + explicit NullableOStream(S *os) : mOs(os) {} NullableOStream &operator=(S &os) { mOs = &os; return *this; @@ -57,7 +57,7 @@ public: S& buf() const { return *mOs; } - operator bool() const { + operator bool() const { // NOLINT(google-explicit-constructor) return mOs != nullptr; } private: diff --git a/cmds/lshal/TableEntry.h b/cmds/lshal/TableEntry.h index 7294b0a134..601b7e25f9 100644 --- a/cmds/lshal/TableEntry.h +++ b/cmds/lshal/TableEntry.h @@ -149,7 +149,7 @@ using TableEntryCompare = std::function&& tables) : mTables(std::move(tables)) {} + explicit MergedTable(std::vector&& tables) : mTables(std::move(tables)) {} TextTable createTextTable(); private: std::vector mTables; diff --git a/cmds/lshal/TextTable.h b/cmds/lshal/TextTable.h index 91d522aef7..301b4bd969 100644 --- a/cmds/lshal/TextTable.h +++ b/cmds/lshal/TextTable.h @@ -33,11 +33,11 @@ public: TextTableRow() {} // A row of cells. - TextTableRow(std::vector&& v) : mFields(std::move(v)) {} + explicit TextTableRow(std::vector&& v) : mFields(std::move(v)) {} // A single comment string. - TextTableRow(std::string&& s) : mLine(std::move(s)) {} - TextTableRow(const std::string& s) : mLine(s) {} + explicit TextTableRow(std::string&& s) : mLine(std::move(s)) {} + explicit TextTableRow(const std::string& s) : mLine(s) {} // Whether this row is an actual row of cells. bool isRow() const { return !fields().empty(); } diff --git a/cmds/lshal/Timeout.h b/cmds/lshal/Timeout.h index 58119a6fcf..46d817759d 100644 --- a/cmds/lshal/Timeout.h +++ b/cmds/lshal/Timeout.h @@ -29,7 +29,7 @@ static constexpr std::chrono::milliseconds IPC_CALL_WAIT{500}; class BackgroundTaskState { public: - BackgroundTaskState(std::function &&func) + explicit BackgroundTaskState(std::function &&func) : mFunc(std::forward(func)) {} void notify() { std::unique_lock lock(mMutex); diff --git a/cmds/lshal/test.cpp b/cmds/lshal/test.cpp index 8d7405b89e..fc8d58b3d8 100644 --- a/cmds/lshal/test.cpp +++ b/cmds/lshal/test.cpp @@ -191,7 +191,7 @@ public: // expose protected fields and methods for ListCommand class MockListCommand : public ListCommand { public: - MockListCommand(Lshal* lshal) : ListCommand(*lshal) {} + explicit MockListCommand(Lshal* lshal) : ListCommand(*lshal) {} Status parseArgs(const Arg& arg) { return ListCommand::parseArgs(arg); } Status main(const Arg& arg) { return ListCommand::main(arg); } @@ -308,7 +308,7 @@ static hidl_hash getHashFromId(pid_t serverId) { // Fake service returned by mocked IServiceManager::get. class TestService : public IBase { public: - TestService(pid_t id) : mId(id) {} + explicit TestService(pid_t id) : mId(id) {} hardware::Return getDebugInfo(getDebugInfo_cb cb) override { cb({ mId /* pid */, getPtr(mId), DebugInfo::Architecture::IS_64BIT }); return hardware::Void();