build: enable and fix -Wshadow
Shadow names can be prone to bugs. Enable the warning to avoid them in
the future. Tested by building and running the unit tests.
Change-Id: Ic3227675f4ff40d266ae2a60c66c894f16e5888e
Signed-off-by: Brad Bishop <bradbish@qti.qualcomm.com>
diff --git a/fail-monitor/monitor.hpp b/fail-monitor/monitor.hpp
index 65bb810..7512474 100644
--- a/fail-monitor/monitor.hpp
+++ b/fail-monitor/monitor.hpp
@@ -45,12 +45,12 @@
*
* @param[in] sourceUnit - the source unit
* @param[in] targetUnit - the target unit
- * @param[in] action - the action to run on the target
+ * @param[in] targetAction - the action to run on the target
*/
Monitor(const std::string& sourceUnit, const std::string& targetUnit,
- Action action) :
+ Action targetAction) :
bus(sdbusplus::bus::new_default()), source(sourceUnit),
- target(targetUnit), action(action)
+ target(targetUnit), action(targetAction)
{}
/**
diff --git a/meson.build b/meson.build
index 4508e20..d7b8132 100644
--- a/meson.build
+++ b/meson.build
@@ -32,6 +32,7 @@
'-Wlogical-op',
'-Wunused-parameter',
'-Wdouble-promotion',
+ '-Wshadow',
language: 'cpp',
)
endif
diff --git a/src/associations.cpp b/src/associations.cpp
index 3293b4e..880b382 100644
--- a/src/associations.cpp
+++ b/src/associations.cpp
@@ -467,7 +467,7 @@
addSingleAssociation(io, server, assocPath, endpointPath, owner,
ownerPath, assocMaps);
}
- catch (const sdbusplus::exception_t& e)
+ catch (const sdbusplus::exception_t& ex)
{
// In some case the interface could not be created on DBus and an
// exception is thrown. mapper has no control of the interface/path
@@ -475,7 +475,7 @@
// association request.
std::cerr << "Error adding association: assocPath " << assocPath
<< ", endpointPath " << endpointPath
- << ", what: " << e.what() << "\n";
+ << ", what: " << ex.what() << "\n";
}
// Not pending anymore
@@ -515,10 +515,11 @@
auto a = std::find_if(
assocs.begin(), assocs.end(),
[&endpointPath, &otherPath](const auto& ap) {
- const auto& endpoints = ap.second;
- auto endpoint = std::find(
- endpoints.begin(), endpoints.end(), otherPath);
- if (endpoint != endpoints.end())
+ const auto& otherEndpoints = ap.second;
+ auto endpoint =
+ std::find(otherEndpoints.begin(),
+ otherEndpoints.end(), otherPath);
+ if (endpoint != otherEndpoints.end())
{
return ap.first.starts_with(endpointPath + '/');
}
diff --git a/src/handler.cpp b/src/handler.cpp
index 9a5244e..902ae66 100644
--- a/src/handler.cpp
+++ b/src/handler.cpp
@@ -72,19 +72,19 @@
}
else
{
- for (const auto& interfaceMap : objectPath.second)
+ for (const auto& connectionInterfaces : objectPath.second)
{
std::vector<std::string> output(std::min(
- interfaces.size(), interfaceMap.second.size()));
+ interfaces.size(), connectionInterfaces.second.size()));
// Return iterator points at the first output elemtn,
// meaning that there are no intersections.
if (std::set_intersection(
interfaces.begin(), interfaces.end(),
- interfaceMap.second.begin(),
- interfaceMap.second.end(), output.begin()) !=
- output.begin())
+ connectionInterfaces.second.begin(),
+ connectionInterfaces.second.end(),
+ output.begin()) != output.begin())
{
- addObjectMapResult(ret, thisPath, interfaceMap);
+ addObjectMapResult(ret, thisPath, connectionInterfaces);
}
}
}
@@ -112,18 +112,19 @@
{
return pathRef->second;
}
- for (const auto& interfaceMap : pathRef->second)
+ for (const auto& connectionInterfaces : pathRef->second)
{
std::vector<std::string> output(
- std::min(interfaces.size(), interfaceMap.second.size()));
+ std::min(interfaces.size(), connectionInterfaces.second.size()));
// Return iterator points at the first output elemtn,
// meaning that there are no intersections.
if (std::set_intersection(interfaces.begin(), interfaces.end(),
- interfaceMap.second.begin(),
- interfaceMap.second.end(), output.begin()) !=
- output.begin())
+ connectionInterfaces.second.begin(),
+ connectionInterfaces.second.end(),
+ output.begin()) != output.begin())
{
- results.emplace(interfaceMap.first, interfaceMap.second);
+ results.emplace(connectionInterfaces.first,
+ connectionInterfaces.second);
}
}
@@ -183,20 +184,20 @@
thisPath.end(), '/');
if (thisDepth <= depth)
{
- for (const auto& interfaceMap : objectPath.second)
+ for (const auto& connectionInterfaces : objectPath.second)
{
std::vector<std::string> output(std::min(
- interfaces.size(), interfaceMap.second.size()));
+ interfaces.size(), connectionInterfaces.second.size()));
// Return iterator points at the first output elemtn,
// meaning that there are no intersections.
if (std::set_intersection(
interfaces.begin(), interfaces.end(),
- interfaceMap.second.begin(),
- interfaceMap.second.end(),
+ connectionInterfaces.second.begin(),
+ connectionInterfaces.second.end(),
output.begin()) != output.begin() ||
interfaces.empty())
{
- addObjectMapResult(ret, thisPath, interfaceMap);
+ addObjectMapResult(ret, thisPath, connectionInterfaces);
}
}
}
@@ -254,17 +255,17 @@
if (thisDepth <= depth)
{
bool add = interfaces.empty();
- for (const auto& interfaceMap : objectPath.second)
+ for (const auto& connectionInterfaces : objectPath.second)
{
std::vector<std::string> output(std::min(
- interfaces.size(), interfaceMap.second.size()));
+ interfaces.size(), connectionInterfaces.second.size()));
// Return iterator points at the first output elemtn,
// meaning that there are no intersections.
if (std::set_intersection(
interfaces.begin(), interfaces.end(),
- interfaceMap.second.begin(),
- interfaceMap.second.end(), output.begin()) !=
- output.begin())
+ connectionInterfaces.second.begin(),
+ connectionInterfaces.second.end(),
+ output.begin()) != output.begin())
{
add = true;
break;
@@ -388,14 +389,15 @@
}
if (thisPath.starts_with(objectPath))
{
- for (const auto& interfaceMap : path.second)
+ for (const auto& connectionInterfaces : path.second)
{
- std::vector<std::string> tempoutput(
- std::min(interfaces.size(), interfaceMap.second.size()));
- if (std::set_intersection(
- interfaces.begin(), interfaces.end(),
- interfaceMap.second.begin(), interfaceMap.second.end(),
- tempoutput.begin()) != tempoutput.begin())
+ std::vector<std::string> tempoutput(std::min(
+ interfaces.size(), connectionInterfaces.second.size()));
+ if (std::set_intersection(interfaces.begin(), interfaces.end(),
+ connectionInterfaces.second.begin(),
+ connectionInterfaces.second.end(),
+ tempoutput.begin()) !=
+ tempoutput.begin())
{
output.emplace_back(thisPath);
break;
diff --git a/src/main.cpp b/src/main.cpp
index e84abfd..b79d722 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -67,18 +67,20 @@
InProgressIntrospect& operator=(const InProgressIntrospect&) = delete;
InProgressIntrospect& operator=(InProgressIntrospect&&) = delete;
InProgressIntrospect(
- sdbusplus::asio::connection* systemBus, boost::asio::io_context& io,
- const std::string& processName, AssociationMaps& am
+ sdbusplus::asio::connection* systemBusConnection,
+ boost::asio::io_context& ioContext,
+ const std::string& introspectProcessName, AssociationMaps& am
#ifdef MAPPER_ENABLE_DEBUG
,
std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>>
- globalStartTime
+ globalIntrospectStartTime
#endif
) :
- systemBus(systemBus), io(io), processName(processName), assocMaps(am)
+ systemBus(systemBusConnection), io(ioContext),
+ processName(introspectProcessName), assocMaps(am)
#ifdef MAPPER_ENABLE_DEBUG
,
- globalStartTime(std::move(globalStartTime)),
+ globalStartTime(std::move(globalIntrospectStartTime)),
processStartTime(std::chrono::steady_clock::now())
#endif
{}
diff --git a/src/test/associations.cpp b/src/test/associations.cpp
index fe0a826..ca31f41 100644
--- a/src/test/associations.cpp
+++ b/src/test/associations.cpp
@@ -499,23 +499,23 @@
ASSERT_EQ(associationData.size(), 2);
{
- auto ad = std::find_if(
+ auto it = std::find_if(
associationData.begin(), associationData.end(),
[](const auto& ad) { return std::get<0>(ad) == "ownerA"; });
- ASSERT_NE(ad, associationData.end());
+ ASSERT_NE(it, associationData.end());
- auto& a = std::get<1>(*ad);
+ auto& a = std::get<1>(*it);
ASSERT_EQ(std::get<0>(a), "type0");
ASSERT_EQ(std::get<1>(a), "typeA");
ASSERT_EQ(std::get<2>(a), "pathA");
}
{
- auto ad = std::find_if(
+ auto it = std::find_if(
associationData.begin(), associationData.end(),
[](const auto& ad) { return std::get<0>(ad) == "ownerB"; });
- ASSERT_NE(ad, associationData.end());
+ ASSERT_NE(it, associationData.end());
- auto& a = std::get<1>(*ad);
+ auto& a = std::get<1>(*it);
ASSERT_EQ(std::get<0>(a), "type1");
ASSERT_EQ(std::get<1>(a), "typeB");
ASSERT_EQ(std::get<2>(a), "pathX");