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
diff --git a/cmds/lshal/Command.h b/cmds/lshal/Command.h
index 4f128ab..e19e3f7 100644
--- a/cmds/lshal/Command.h
+++ b/cmds/lshal/Command.h
@@ -27,7 +27,7 @@
// 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 6e12008..3c3f56f 100644
--- a/cmds/lshal/DebugCommand.h
+++ b/cmds/lshal/DebugCommand.h
@@ -31,7 +31,7 @@
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 cc709f8..da0cba6 100644
--- a/cmds/lshal/HelpCommand.h
+++ b/cmds/lshal/HelpCommand.h
@@ -31,7 +31,7 @@
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 3f7321d..85195fc 100644
--- a/cmds/lshal/ListCommand.h
+++ b/cmds/lshal/ListCommand.h
@@ -57,7 +57,7 @@
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 ab37a04..737d3a2 100644
--- a/cmds/lshal/NullableOStream.h
+++ b/cmds/lshal/NullableOStream.h
@@ -25,8 +25,8 @@
template<typename S>
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 @@
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 7294b0a..601b7e2 100644
--- a/cmds/lshal/TableEntry.h
+++ b/cmds/lshal/TableEntry.h
@@ -149,7 +149,7 @@
class MergedTable {
public:
- MergedTable(std::vector<const Table*>&& tables) : mTables(std::move(tables)) {}
+ explicit MergedTable(std::vector<const Table*>&& tables) : mTables(std::move(tables)) {}
TextTable createTextTable();
private:
std::vector<const Table*> mTables;
diff --git a/cmds/lshal/TextTable.h b/cmds/lshal/TextTable.h
index 91d522a..301b4bd 100644
--- a/cmds/lshal/TextTable.h
+++ b/cmds/lshal/TextTable.h
@@ -33,11 +33,11 @@
TextTableRow() {}
// A row of cells.
- TextTableRow(std::vector<std::string>&& v) : mFields(std::move(v)) {}
+ explicit TextTableRow(std::vector<std::string>&& 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 58119a6..46d8177 100644
--- a/cmds/lshal/Timeout.h
+++ b/cmds/lshal/Timeout.h
@@ -29,7 +29,7 @@
class BackgroundTaskState {
public:
- BackgroundTaskState(std::function<void(void)> &&func)
+ explicit BackgroundTaskState(std::function<void(void)> &&func)
: mFunc(std::forward<decltype(func)>(func)) {}
void notify() {
std::unique_lock<std::mutex> lock(mMutex);
diff --git a/cmds/lshal/test.cpp b/cmds/lshal/test.cpp
index 8d7405b..fc8d58b 100644
--- a/cmds/lshal/test.cpp
+++ b/cmds/lshal/test.cpp
@@ -191,7 +191,7 @@
// 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 @@
// 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<void> getDebugInfo(getDebugInfo_cb cb) override {
cb({ mId /* pid */, getPtr(mId), DebugInfo::Architecture::IS_64BIT });
return hardware::Void();