Fix variable shadow warnings in sdbusplus
-Wshadow is useful for subprojects to enable, because it can find bugs
in common variable names (err, r, i, etc). With these changes, projects
can now build sdbusplus with -Wshadow enabled.
The changes fall into a couple buckets. The first is for constructor
variables that match the member variable name. In these cases, "_in" is
appended to the end of the constructor variable name.
The second is a case where the variable "r" was used for return codes
twice. One instance is changed to "ret".
With these changes, projects can compile with -Wshadow enabled without
warnings.
Change-Id: Ia33a6f8306473c616f6278bb848460167e5463ef
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/include/sdbusplus/message/native_types.hpp b/include/sdbusplus/message/native_types.hpp
index 287057f..4d6c56e 100644
--- a/include/sdbusplus/message/native_types.hpp
+++ b/include/sdbusplus/message/native_types.hpp
@@ -27,8 +27,8 @@
string_wrapper& operator=(string_wrapper&&) = default;
~string_wrapper() = default;
- string_wrapper(const std::string& str) : str(str) {}
- string_wrapper(std::string&& str) : str(std::move(str)) {}
+ string_wrapper(const std::string& str_in) : str(str_in) {}
+ string_wrapper(std::string&& str_in) : str(std::move(str_in)) {}
operator const std::string&() const volatile&
{
@@ -91,8 +91,8 @@
string_path_wrapper& operator=(string_path_wrapper&&) = default;
~string_path_wrapper() = default;
- string_path_wrapper(const std::string& str) : str(str) {}
- string_path_wrapper(std::string&& str) : str(std::move(str)) {}
+ string_path_wrapper(const std::string& str_in) : str(str_in) {}
+ string_path_wrapper(std::string&& str_in) : str(std::move(str_in)) {}
operator const std::string&() const volatile&
{
diff --git a/include/sdbusplus/message/read.hpp b/include/sdbusplus/message/read.hpp
index ff287f2..066be20 100644
--- a/include/sdbusplus/message/read.hpp
+++ b/include/sdbusplus/message/read.hpp
@@ -412,16 +412,16 @@
{
std::string str{};
sdbusplus::message::read(intf, m, str);
- auto r =
+ auto ret =
sdbusplus::message::convert_from_string<std::variant<Args...>>(
str);
- if (!r)
+ if (!ret)
{
throw sdbusplus::exception::InvalidEnumString();
}
- s = std::move(*r);
+ s = std::move(*ret);
}
else // otherise, read it out directly.
{
diff --git a/include/sdbusplus/server/transaction.hpp b/include/sdbusplus/server/transaction.hpp
index 844883f..50c9677 100644
--- a/include/sdbusplus/server/transaction.hpp
+++ b/include/sdbusplus/server/transaction.hpp
@@ -33,8 +33,8 @@
struct Transaction
{
- Transaction(sdbusplus::bus_t& bus, sdbusplus::message_t& msg) :
- bus(bus), msg(msg)
+ Transaction(sdbusplus::bus_t& bus_in, sdbusplus::message_t& msg_in) :
+ bus(bus_in), msg(msg_in)
{}
sdbusplus::bus_t& bus;
diff --git a/src/exception.cpp b/src/exception.cpp
index 804fab8..a7a3596 100644
--- a/src/exception.cpp
+++ b/src/exception.cpp
@@ -21,14 +21,16 @@
return EIO;
}
-SdBusError::SdBusError(int error, const char* prefix, SdBusInterface* intf) :
- error(SD_BUS_ERROR_NULL), intf(intf)
+SdBusError::SdBusError(int error_in, const char* prefix,
+ SdBusInterface* intf_in) :
+ error(SD_BUS_ERROR_NULL),
+ intf(intf_in)
{
// We can't check the output of intf->sd_bus_error_set_errno() because
// it returns the input errorcode. We don't want to try and guess
// possible error statuses. Instead, check to see if the error was
// constructed to determine success.
- intf->sd_bus_error_set_errno(&this->error, error);
+ intf->sd_bus_error_set_errno(&this->error, error_in);
if (!intf->sd_bus_error_is_set(&this->error))
{
throw std::runtime_error("Failed to create SdBusError");
@@ -37,13 +39,13 @@
populateMessage(prefix);
}
-SdBusError::SdBusError(sd_bus_error* error, const char* prefix,
- SdBusInterface* intf) :
- error(*error),
- intf(intf)
+SdBusError::SdBusError(sd_bus_error* error_in, const char* prefix,
+ SdBusInterface* intf_in) :
+ error(*error_in),
+ intf(intf_in)
{
// We own the error so remove the caller's reference
- *error = SD_BUS_ERROR_NULL;
+ *error_in = SD_BUS_ERROR_NULL;
populateMessage(prefix);
}