Skip to content

Commit 67b3691

Browse files
authored
Fix Wshadow errors and enforce it (#3617)
* Fix Wshadow errors and enforce it Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com> * Remove workaround for pluginlib * This was only needed because it was included transitively * By finding and linking properly, the compiler flags get propogated as SYSTEM correctly Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com> --------- Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com>
1 parent d985452 commit 67b3691

File tree

11 files changed

+46
-47
lines changed

11 files changed

+46
-47
lines changed

nav2_amcl/src/pf/eig3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static void tred2(double V[n][n], double d[n], double e[n])
4343
// Fortran subroutine in EISPACK.
4444

4545
int i, j, k;
46-
double f, g, h, hh;
46+
double f, g, hh;
4747
for (j = 0; j < n; j++) {
4848
d[j] = V[n - 1][j];
4949
}
@@ -122,7 +122,7 @@ static void tred2(double V[n][n], double d[n], double e[n])
122122
for (i = 0; i < n - 1; i++) {
123123
V[n - 1][i] = V[i][i];
124124
V[i][i] = 1.0;
125-
h = d[i + 1];
125+
const double h = d[i + 1];
126126
if (h != 0.0) {
127127
for (k = 0; k <= i; k++) {
128128
d[k] = V[k][i + 1] / h;

nav2_common/cmake/nav2_package.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ macro(nav2_package)
3737
endif()
3838

3939
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
40-
add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wdeprecated -fPIC )
40+
add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wdeprecated -fPIC -Wshadow)
4141
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>")
4242
endif()
4343

nav2_constrained_smoother/include/nav2_constrained_smoother/smoother.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ class Smoother
194194
// update cusp zone costmap weights
195195
if (is_cusp) {
196196
double len_to_cusp = current_segment_len;
197-
for (int i = potential_cusp_funcs.size() - 1; i >= 0; i--) {
198-
auto & f = potential_cusp_funcs[i];
197+
for (int i_cusp = potential_cusp_funcs.size() - 1; i_cusp >= 0; i_cusp--) {
198+
auto & f = potential_cusp_funcs[i_cusp];
199199
double new_weight =
200200
params.cusp_costmap_weight * (1.0 - len_to_cusp / cusp_half_length) +
201201
params.costmap_weight * len_to_cusp / cusp_half_length;

nav2_costmap_2d/plugins/denoise_layer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ DenoiseLayer::removeSinglePixels(Image<uint8_t> & image) const
171171
return v == NO_INFORMATION ? FREE_SPACE : v;
172172
};
173173
auto max = [&](const std::initializer_list<uint8_t> lst) {
174-
std::array<uint8_t, 3> buf = {
174+
std::array<uint8_t, 3> rbuf = {
175175
replace_to_free(*lst.begin()),
176176
replace_to_free(*(lst.begin() + 1)),
177177
replace_to_free(*(lst.begin() + 2))
178178
};
179-
return *std::max_element(buf.begin(), buf.end());
179+
return *std::max_element(rbuf.begin(), rbuf.end());
180180
};
181181
dilate(image, max_neighbors_image, group_connectivity_type_, max);
182182
} else {

nav2_costmap_2d/test/integration/test_costmap_topic_collision_checker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class DummyFootprintSubscriber : public nav2_costmap_2d::FootprintSubscriber
7373
DummyFootprintSubscriber(
7474
nav2_util::LifecycleNode::SharedPtr node,
7575
std::string & topic_name,
76-
tf2_ros::Buffer & tf_)
77-
: FootprintSubscriber(node, topic_name, tf_)
76+
tf2_ros::Buffer & tf)
77+
: FootprintSubscriber(node, topic_name, tf)
7878
{}
7979

8080
void setFootprint(geometry_msgs::msg::PolygonStamped::SharedPtr msg)

nav2_dwb_controller/dwb_core/src/dwb_local_planner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ DWBLocalPlanner::transformGlobalPlan(
526526
// from the robot using integrated distance
527527
auto transformation_end = std::find_if(
528528
transformation_begin, global_plan_.poses.end(),
529-
[&](const auto & pose) {
530-
return euclidean_distance(pose, robot_pose.pose) > transform_end_threshold;
529+
[&](const auto & global_plan_pose) {
530+
return euclidean_distance(global_plan_pose, robot_pose.pose) > transform_end_threshold;
531531
});
532532

533533
// Transform the near part of the global plan into the robot's frame of reference.

nav2_dwb_controller/dwb_critics/test/obstacle_footprint_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ TEST(ObstacleFootprint, GetOrientedFootprint)
105105
pose.theta = theta;
106106
footprint_after = dwb_critics::getOrientedFootprint(pose, footprint_before);
107107

108-
uint i;
109-
for (i = 0; i < footprint_before.size(); i++) {
108+
for (uint i = 0; i < footprint_before.size(); i++) {
110109
ASSERT_EQ(rotate_origin(footprint_before[i], theta), footprint_after[i]);
111110
}
112111

nav2_navfn_planner/src/navfn.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,10 @@ inline void
421421
NavFn::updateCell(int n)
422422
{
423423
// get neighbors
424-
float u, d, l, r;
425-
l = potarr[n - 1];
426-
r = potarr[n + 1];
427-
u = potarr[n - nx];
428-
d = potarr[n + nx];
424+
const float l = potarr[n - 1];
425+
const float r = potarr[n + 1];
426+
const float u = potarr[n - nx];
427+
const float d = potarr[n + nx];
429428
// ROS_INFO("[Update] c: %0.1f l: %0.1f r: %0.1f u: %0.1f d: %0.1f\n",
430429
// potarr[n], l, r, u, d);
431430
// ROS_INFO("[Update] cost: %d\n", costarr[n]);
@@ -452,8 +451,8 @@ NavFn::updateCell(int n)
452451
// use quadratic approximation
453452
// might speed this up through table lookup, but still have to
454453
// do the divide
455-
float d = dc / hf;
456-
float v = -0.2301 * d * d + 0.5307 * d + 0.7040;
454+
const float div = dc / hf;
455+
const float v = -0.2301 * div * div + 0.5307 * div + 0.7040;
457456
pot = ta + hf * v;
458457
}
459458

@@ -496,11 +495,10 @@ inline void
496495
NavFn::updateCellAstar(int n)
497496
{
498497
// get neighbors
499-
float u, d, l, r;
500-
l = potarr[n - 1];
501-
r = potarr[n + 1];
502-
u = potarr[n - nx];
503-
d = potarr[n + nx];
498+
float l = potarr[n - 1];
499+
float r = potarr[n + 1];
500+
float u = potarr[n - nx];
501+
float d = potarr[n + nx];
504502
// ROS_INFO("[Update] c: %0.1f l: %0.1f r: %0.1f u: %0.1f d: %0.1f\n",
505503
// potarr[n], l, r, u, d);
506504
// ROS_INFO("[Update] cost of %d: %d\n", n, costarr[n]);
@@ -527,8 +525,8 @@ NavFn::updateCellAstar(int n)
527525
// use quadratic approximation
528526
// might speed this up through table lookup, but still have to
529527
// do the divide
530-
float d = dc / hf;
531-
float v = -0.2301 * d * d + 0.5307 * d + 0.7040;
528+
const float div = dc / hf;
529+
const float v = -0.2301 * div * div + 0.5307 * div + 0.7040;
532530
pot = ta + hf * v;
533531
}
534532

@@ -834,22 +832,22 @@ NavFn::calcPath(int n, int * st)
834832
// check eight neighbors to find the lowest
835833
int minc = stc;
836834
int minp = potarr[stc];
837-
int st = stcpx - 1;
838-
if (potarr[st] < minp) {minp = potarr[st]; minc = st;}
839-
st++;
840-
if (potarr[st] < minp) {minp = potarr[st]; minc = st;}
841-
st++;
842-
if (potarr[st] < minp) {minp = potarr[st]; minc = st;}
843-
st = stc - 1;
844-
if (potarr[st] < minp) {minp = potarr[st]; minc = st;}
845-
st = stc + 1;
846-
if (potarr[st] < minp) {minp = potarr[st]; minc = st;}
847-
st = stcnx - 1;
848-
if (potarr[st] < minp) {minp = potarr[st]; minc = st;}
849-
st++;
850-
if (potarr[st] < minp) {minp = potarr[st]; minc = st;}
851-
st++;
852-
if (potarr[st] < minp) {minp = potarr[st]; minc = st;}
835+
int sti = stcpx - 1;
836+
if (potarr[sti] < minp) {minp = potarr[sti]; minc = sti;}
837+
sti++;
838+
if (potarr[sti] < minp) {minp = potarr[sti]; minc = sti;}
839+
sti++;
840+
if (potarr[sti] < minp) {minp = potarr[sti]; minc = sti;}
841+
sti = stc - 1;
842+
if (potarr[sti] < minp) {minp = potarr[sti]; minc = sti;}
843+
sti = stc + 1;
844+
if (potarr[sti] < minp) {minp = potarr[sti]; minc = sti;}
845+
sti = stcnx - 1;
846+
if (potarr[sti] < minp) {minp = potarr[sti]; minc = sti;}
847+
sti++;
848+
if (potarr[sti] < minp) {minp = potarr[sti]; minc = sti;}
849+
sti++;
850+
if (potarr[sti] < minp) {minp = potarr[sti]; minc = sti;}
853851
stc = minc;
854852
dx = 0;
855853
dy = 0;

nav2_regulated_pure_pursuit_controller/src/path_handler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ nav_msgs::msg::Path PathHandler::transformGlobalPlan(
7777
const double max_costmap_extent = getCostmapMaxExtent();
7878
auto transformation_end = std::find_if(
7979
transformation_begin, global_plan_.poses.end(),
80-
[&](const auto & pose) {
81-
return euclidean_distance(pose, robot_pose) > max_costmap_extent;
80+
[&](const auto & global_plan_pose) {
81+
return euclidean_distance(global_plan_pose, robot_pose) > max_costmap_extent;
8282
});
8383

8484
// Lambda to transform a PoseStamped from global frame to local

nav2_smoother/test/test_smoother_server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ class DummyFootprintSubscriber : public nav2_costmap_2d::FootprintSubscriber
158158
DummyFootprintSubscriber(
159159
nav2_util::LifecycleNode::SharedPtr node,
160160
const std::string & topic_name,
161-
tf2_ros::Buffer & tf_)
162-
: FootprintSubscriber(node, topic_name, tf_)
161+
tf2_ros::Buffer & tf)
162+
: FootprintSubscriber(node, topic_name, tf)
163163
{
164164
auto footprint = std::make_shared<geometry_msgs::msg::PolygonStamped>();
165165
footprint->header.frame_id = "base_link"; // global frame = robot frame to avoid tf lookup

0 commit comments

Comments
 (0)