Skip to content

ament_clang_tidy outputs sysyem header errors despite --system-header is false as default #502

@pucciland95

Description

@pucciland95

Hi,

I am trying to integrate ament_cmake_clang_tidy in my ROS2 Humble codebase, but I do not understand why it outputs errors about the libraries that I am using (i.e. rclcpp). Therefore, the test is failing but not because of my code. The following is a minimal example to reproduce the problem:

Steps:

  1. follow the ros2 tutorial guide about minimal subscriber to create minimal workspace.
  2. Build the system with colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
  3. From your ROS2 workspace execute: ament_clang_tidy build/cpp_pubsub/

The output is:

found compilation database for package "cpp_pubsub"...
The invocation of "clang-tidy" failed with error code 1: Command '['/usr/bin/clang-tidy', '-p', 'build/cpp_pubsub', '--header-filter', 'include/cpp_pubsub/.*', '/home/niccolo-hiro/ros/nisa_robot_ws/src/cpp_pubsub/src/publisher_member_function.cpp']' returned non-zero exit status 1.
error: too many errors emitted, stopping now [clang-diagnostic-error]
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:550:10: error: no member named 'optional' in namespace 'std' [clang-diagnostic-error]
    std::optional<CallbackInfoVariant>
    ~~~~~^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:550:19: error: use of undeclared identifier 'CallbackInfoVariant' [clang-diagnostic-error]
    std::optional<CallbackInfoVariant>
                  ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:551:5: error: use of undeclared identifier 'optional_pending_request' [clang-diagnostic-error]
    optional_pending_request = this->get_and_erase_pending_request(request_header->sequence_number);
    ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:552:10: error: use of undeclared identifier 'optional_pending_request' [clang-diagnostic-error]
    if (!optional_pending_request) {
         ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:555:21: error: use of undeclared identifier 'optional_pending_request' [clang-diagnostic-error]
    auto & value = *optional_pending_request;
                    ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:558:14: error: no member named 'holds_alternative' in namespace 'std' [clang-diagnostic-error]
    if (std::holds_alternative<Promise>(value)) {
        ~~~~~^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:558:32: error: unexpected type name 'Promise': expected expression [clang-diagnostic-error]
    if (std::holds_alternative<Promise>(value)) {
                               ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:561:21: error: no member named 'holds_alternative' in namespace 'std' [clang-diagnostic-error]
    } else if (std::holds_alternative<CallbackTypeValueVariant>(value)) {
               ~~~~~^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:561:39: error: unexpected type name 'CallbackTypeValueVariant': expected expression [clang-diagnostic-error]
    } else if (std::holds_alternative<CallbackTypeValueVariant>(value)) {
                                      ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:568:21: error: no member named 'holds_alternative' in namespace 'std' [clang-diagnostic-error]
    } else if (std::holds_alternative<CallbackWithRequestTypeValueVariant>(value)) {
               ~~~~~^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:568:39: error: unexpected type name 'CallbackWithRequestTypeValueVariant': expected expression [clang-diagnostic-error]
    } else if (std::holds_alternative<CallbackWithRequestTypeValueVariant>(value)) {
                                      ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:702:10: error: use of class template 'std::lock_guard' requires template arguments [clang-diagnostic-error]
    std::lock_guard guard(pending_requests_mutex_);
         ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_mutex.h:223:11: note: template is declared here
    class lock_guard
          ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:749:10: error: use of class template 'std::lock_guard' requires template arguments [clang-diagnostic-error]
    std::lock_guard guard(pending_requests_mutex_);
         ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_mutex.h:223:11: note: template is declared here
    class lock_guard
          ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:768:10: error: use of class template 'std::lock_guard' requires template arguments [clang-diagnostic-error]
    std::lock_guard guard(pending_requests_mutex_);
         ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_mutex.h:223:11: note: template is declared here
    class lock_guard
          ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:788:36: error: no template named 'variant' in namespace 'std' [clang-diagnostic-error]
  using CallbackInfoVariant = std::variant<
                              ~~~~~^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:794:52: error: unknown type name 'CallbackInfoVariant' [clang-diagnostic-error]
  async_send_request_impl(const Request & request, CallbackInfoVariant value)
                                                   ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:808:8: error: no template named 'optional' in namespace 'std' [clang-diagnostic-error]
  std::optional<CallbackInfoVariant>
  ~~~~~^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:808:17: error: use of undeclared identifier 'CallbackInfoVariant' [clang-diagnostic-error]
  std::optional<CallbackInfoVariant>
                ^
/opt/ros/humble/include/rclcpp/rclcpp/client.hpp:830:7: error: use of undeclared identifier 'CallbackInfoVariant' [clang-diagnostic-error]
      CallbackInfoVariant>>

which as you can see is all related to rclcpp.
Furthrmore, setting in package.xml:

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_cmake_clang_tidy</test_depend>

and in CMakeList.txt:

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

issuing: colcon test --packages-select cpp_pubsub --event-handlers console_direct+ provides exactly the same output.
Am I using this tool incorrectly?

Let me know,

cheers,

Niccolo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions