Skip to content

Commit fb06f56

Browse files
jmachowinskiJanosch Machowinski
andauthored
feat: Switch to c++20 and remove resulting compile warnings (#3124)
Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com> Co-authored-by: Janosch Machowinski <J.Machowinski@cellumation.com>
1 parent e0e3574 commit fb06f56

4 files changed

Lines changed: 20 additions & 20 deletions

File tree

rclcpp/CMakeLists.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ project(rclcpp)
55
find_package(Threads REQUIRED)
66

77
find_package(ament_cmake_ros REQUIRED)
8+
find_package(ament_cmake_ros_core REQUIRED)
89
find_package(ament_index_cpp REQUIRED)
910
find_package(builtin_interfaces REQUIRED)
1011
find_package(libstatistics_collector REQUIRED)
@@ -24,12 +25,6 @@ find_package(rosidl_typesupport_cpp REQUIRED)
2425
find_package(statistics_msgs REQUIRED)
2526
find_package(tracetools REQUIRED)
2627

27-
# TODO(wjwwood): remove this when gtest can build on its own, when using target_compile_features()
28-
# Default to C++17
29-
if(NOT CMAKE_CXX_STANDARD)
30-
set(CMAKE_CXX_STANDARD 17)
31-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
32-
endif()
3328
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
3429
# About -Wno-sign-conversion: With Clang, -Wconversion implies -Wsign-conversion. There are a number of
3530
# implicit sign conversions in rclcpp and gtest.cc, see https://ci.ros2.org/job/ci_osx/9265/.
@@ -193,7 +188,6 @@ foreach(interface_file ${interface_files})
193188
endforeach()
194189

195190
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS})
196-
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
197191
# TODO(wjwwood): address all deprecation warnings and then remove this
198192
if(WIN32)
199193
target_compile_definitions(${PROJECT_NAME} PUBLIC "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS")
@@ -219,6 +213,9 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
219213
statistics_msgs::statistics_msgs
220214
tracetools::tracetools
221215
${CMAKE_THREAD_LIBS_INIT}
216+
# Note we link public on purpose, as we want to export
217+
# the used C++ version as minimum to all consuming packages
218+
ament_cmake_ros_core::ament_ros_defaults
222219
)
223220

224221
target_link_libraries(${PROJECT_NAME} PRIVATE

rclcpp/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<buildtool_depend>python3-empy</buildtool_depend>
2121

2222
<build_depend>ament_index_cpp</build_depend>
23+
<build_depend>ament_index_cpp_core</build_depend>
2324
<build_depend>builtin_interfaces</build_depend>
2425
<build_depend>rcl_interfaces</build_depend>
2526
<build_depend>rosgraph_msgs</build_depend>

rclcpp/src/rclcpp/parameter_event_handler.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ParameterEventHandler::configure_nodes_filter(const std::vector<std::string> & n
8383

8484
if (node_names.empty()) {
8585
// Clear content filter
86-
event_subscription_->set_content_filter("");
86+
event_subscription_->set_content_filter(std::string());
8787
if (event_subscription_->is_cft_enabled()) {
8888
return false;
8989
}
@@ -101,8 +101,9 @@ ParameterEventHandler::configure_nodes_filter(const std::vector<std::string> & n
101101

102102
// Enclose each node name in "'".
103103
std::vector<std::string> quoted_node_names;
104+
const std::string delim("'");
104105
for (const auto & name : node_names) {
105-
quoted_node_names.push_back("'" + resolve_path(name) + "'");
106+
quoted_node_names.push_back(delim + resolve_path(name) + delim);
106107
}
107108

108109
event_subscription_->set_content_filter(filter_expression, quoted_node_names);
@@ -229,20 +230,21 @@ ParameterEventHandler::Callbacks::event_callback(const rcl_interfaces::msg::Para
229230
std::string
230231
ParameterEventHandler::resolve_path(const std::string & path)
231232
{
232-
std::string full_path;
233+
if (path.empty()) {
234+
return node_base_->get_fully_qualified_name();
235+
}
233236

234-
if (path == "") {
235-
full_path = node_base_->get_fully_qualified_name();
236-
} else {
237-
full_path = path;
238-
if (*path.begin() != '/') {
239-
auto ns = node_base_->get_namespace();
240-
const std::vector<std::string> paths{ns, path};
241-
full_path = (ns == std::string("/")) ? ns + path : rcpputils::join(paths, "/");
237+
if (*path.begin() != '/') {
238+
auto ns = node_base_->get_namespace();
239+
const std::vector<std::string> paths{ns, path};
240+
if(ns == std::string("/")) {
241+
return ns + path;
242242
}
243+
244+
return rcpputils::join(paths, "/");
243245
}
244246

245-
return full_path;
247+
return path;
246248
}
247249

248250
} // namespace rclcpp

rclcpp/test/rclcpp/executors/test_executors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ TYPED_TEST(TestExecutors, testRaceConditionAddNode)
650650
if (should_cancel) {
651651
break;
652652
}
653-
total += k * (i + 42);
653+
total = total + k * (i + 42);
654654
(void)total;
655655
}
656656
});

0 commit comments

Comments
 (0)