Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pucciland95 opened this issue Oct 1, 2024 · 1 comment

Comments

@pucciland95
Copy link

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

@pucciland95 pucciland95 changed the title ament_clang_tidy outputs sysyem header errors despite --system-header is false as defalt ament_clang_tidy outputs sysyem header errors despite --system-header is false as default Oct 1, 2024
@pucciland95
Copy link
Author

Ok, I think I found the problem. The newer versions of rclcpp use c++17. Indeed, adding --extra-arg=-std=c++17 to the clang-tidy command returns only the problems in the provided files. The full command is:

clang-tidy -p <path_to_compile_commands.json> --extra-arg=-std=c++17 <path_to_cpp_file_to_analyse>

Notice that I used clang-tidy and not ament_clang_tidysince the latter does not provide a way to specify such an argument. A solution has already been proposed in #452, but it has been waiting for more than a year.

I will close the issue since my problem has been fixed.

Niccolo

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

No branches or pull requests

1 participant