Skip to content

Commit 66e93dc

Browse files
emersonknappmergify[bot]
authored andcommitted
Fix deprecation warnings for message constants (#750)
Fixes #743 This patch fixes two issues: 1. Code generation for `rosidl_typesupport_introspection_cpp` was overriding user-provided compile definitons, hiding the `-Wdeprecated` warnings in generated code, that users did see in `rosidl_typesupport_fastrtps_cpp`, which was not overriding those compile flags. This inconsistent result confused the issue of why we were seeing deprecation warnings in some portion of the build but not others 1. `#ifdef`s out a variable definition for message constant members that is now deprecated in C++17. In C++14 it was still necessary to define a `static constexpr` member variable outside the class, but as of C++17 those `static constexpr` vars are now automatically inlined so the declaration and definiton are the same line, making the external definition redundant. Signed-off-by: Emerson Knapp <[email protected]> (cherry picked from commit 1228f54)
1 parent 81e9007 commit 66e93dc

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

rosidl_generator_cpp/resource/msg__struct.hpp.em

+3
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,11 @@ template<typename ContainerAllocator>
367367
const @(MSG_TYPE_TO_CPP['wstring'])
368368
@(message.structure.namespaced_type.name)_<ContainerAllocator>::@(c.name) = u"@(escape_wstring(c.value))";
369369
@[ else ]@
370+
#if __cplusplus < 201703L
371+
// static constexpr member variable definitions are only needed in C++14 and below, deprecated in C++17
370372
template<typename ContainerAllocator>
371373
constexpr @(MSG_TYPE_TO_CPP[c.type.typename]) @(message.structure.namespaced_type.name)_<ContainerAllocator>::@(c.name);
374+
#endif // __cplusplus < 201703L
372375
@[ end if]@
373376
@[ if c.name in msvc_common_macros]@
374377
#if defined(_WIN32)

rosidl_typesupport_introspection_cpp/cmake/rosidl_typesupport_introspection_cpp_generate_interfaces.cmake

+5-4
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ if(rosidl_generate_interfaces_LIBRARY_NAME)
100100
endif()
101101
set_property(TARGET ${rosidl_generate_interfaces_TARGET}${_target_suffix}
102102
PROPERTY DEFINE_SYMBOL "ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_BUILDING_DLL")
103+
set_property(TARGET ${rosidl_generate_interfaces_TARGET}${_target_suffix}
104+
PROPERTY CXX_STANDARD 17)
105+
103106
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
104-
set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} PROPERTIES
105-
CXX_STANDARD 17
106-
COMPILE_OPTIONS -Wall -Wextra -Wpedantic
107-
)
107+
target_compile_options(${rosidl_generate_interfaces_TARGET}${_target_suffix}
108+
PRIVATE -Wall -Wextra -Wpedantic)
108109
endif()
109110

110111
target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix}

0 commit comments

Comments
 (0)