Skip to content

Enable capability to build with pedantic flags.#259

Open
leander-dsouza wants to merge 1 commit intoros2:rollingfrom
leander-dsouza:fix-pedantic-errors
Open

Enable capability to build with pedantic flags.#259
leander-dsouza wants to merge 1 commit intoros2:rollingfrom
leander-dsouza:fix-pedantic-errors

Conversation

@leander-dsouza
Copy link
Copy Markdown

@leander-dsouza leander-dsouza commented Apr 21, 2026

Description

  • Let's say we have a demo_pkg as follows:

    .
    ├── CMakeLists.txt
    ├── msg
    │   └── Demo.msg
    └── package.xml

    CMakeLists.txt:

    cmake_minimum_required(VERSION 3.8)
    project(demo_pkg)
    
    find_package(ament_cmake REQUIRED)
    find_package(rosidl_default_generators REQUIRED)
    
    rosidl_generate_interfaces(${PROJECT_NAME}
      "msg/Demo.msg"
    )
    
    ament_package()

    package.xml:

    <?xml version="1.0"?>
    <package format="3">
     <name>demo_pkg</name>
     <version>0.0.1</version>
     <description>Demo messages for testing -Wpedantic</description>
     <maintainer email="test@test.com">test</maintainer>
     <license>Apache-2.0</license>
    
     <buildtool_depend>ament_cmake</buildtool_depend>
     <buildtool_depend>rosidl_default_generators</buildtool_depend>
    
     <exec_depend>rosidl_default_runtime</exec_depend>
    
     <member_of_group>rosidl_interface_packages</member_of_group>
    </package>

    Demo.msg:

    string name
  • Building with the -Wpedantic flag causes the following errors:

    $ colcon build --packages-select demo_pkg --cmake-args -DCMAKE_C_FLAGS="-Wpedantic -Werror"
    
    /ros2_ws/build/demo_msgs/rosidl_generator_py/demo_msgs/_demo_msgs_s.ep.rosidl_typesupport_c.c:59:5: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
      59 |     (void *)&demo_msgs__msg__demo__create_ros_message,
         |     ^
    /ros2_ws/build/demo_msgs/rosidl_generator_py/demo_msgs/_demo_msgs_s.ep.rosidl_typesupport_c.c:78:5: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
      78 |     (void *)&demo_msgs__msg__demo__destroy_ros_message,
         |     ^
    /ros2_ws/build/demo_msgs/rosidl_generator_py/demo_msgs/_demo_msgs_s.ep.rosidl_typesupport_c.c:97:5: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
      97 |     (void *)&demo_msgs__msg__demo__convert_from_py,
         |     ^
    /ros2_ws/build/demo_msgs/rosidl_generator_py/demo_msgs/_demo_msgs_s.ep.rosidl_typesupport_c.c:116:5: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
     116 |     (void *)&demo_msgs__msg__demo__convert_to_py,
  • This is because -Wpedantic prevents casting a function pointer directly to void *.

  • Therefore, instead of casting, the bytes of the function pointer are copied into a void * via memcpy through the added contribution.

  • To test this fix, rosidl and rosidl_typesupport_fastrps needs to compiled from source.

Fixes # (issue)

  • This enables the capability to build packages with the pedantic warning flag enabled.

Is this user-facing behavior change?

Yes, it is a user-facing behavior change, as now new packages can be passed with - --cmake-args -DCMAKE_C_FLAGS="-Wpedantic"

Did you use Generative AI?

  • N/A

Additional Information

  • N/A

Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com>
@leander-dsouza leander-dsouza marked this pull request as ready for review April 21, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant