Skip to content

Commit

Permalink
Fix deprecation warnings for message constants (#750)
Browse files Browse the repository at this point in the history
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 <emerson.b.knapp@gmail.com>
(cherry picked from commit 1228f54)
  • Loading branch information
emersonknapp authored and mergify[bot] committed Jun 8, 2023
1 parent a57baea commit 882d950
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions rosidl_generator_cpp/resource/msg__struct.hpp.em
Expand Up @@ -377,8 +377,11 @@ template<typename ContainerAllocator>
const @(MSG_TYPE_TO_CPP['wstring'])
@(message.structure.namespaced_type.name)_<ContainerAllocator>::@(c.name) = u"@(escape_wstring(c.value))";
@[ else ]@
#if __cplusplus < 201703L
// static constexpr member variable definitions are only needed in C++14 and below, deprecated in C++17
template<typename ContainerAllocator>
constexpr @(MSG_TYPE_TO_CPP[c.type.typename]) @(message.structure.namespaced_type.name)_<ContainerAllocator>::@(c.name);
#endif // __cplusplus < 201703L
@[ end if]@
@[ if c.name in msvc_common_macros]@
#if defined(_WIN32)
Expand Down
Expand Up @@ -100,11 +100,12 @@ if(rosidl_generate_interfaces_LIBRARY_NAME)
endif()
set_property(TARGET ${rosidl_generate_interfaces_TARGET}${_target_suffix}
PROPERTY DEFINE_SYMBOL "ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_BUILDING_DLL")
set_property(TARGET ${rosidl_generate_interfaces_TARGET}${_target_suffix}
PROPERTY CXX_STANDARD 17)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} PROPERTIES
CXX_STANDARD 17
COMPILE_OPTIONS -Wall -Wextra -Wpedantic
)
target_compile_options(${rosidl_generate_interfaces_TARGET}${_target_suffix}
PRIVATE -Wall -Wextra -Wpedantic)
endif()

target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix}
Expand Down

0 comments on commit 882d950

Please sign in to comment.