ros2 / ros2/rclcpp

cppcoreguidelines-pro-bounds-array-to-pointer-decay on RCLCPP_* macros

Open
#1,848 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

Bug report

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • binaries
  • Version or commit hash:
    • rolling
  • DDS implementation:
    • default
  • Client library (if applicable):
    • rclcpp
Steps to reproduce issue

1. Enable cppcoreguidelines-pro-bounds-array-to-pointer-decay in clang-tidy
2. Run clang-tidy over anything that has a RCLCPP_* macro in it

Expected behavior

No clang-tidy warnings.

Actual behavior
error: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay,-warnings-as-errors]
    RCLCPP_WARN(logger_, "yay, clang-tidy warning!");
    ^
/opt/ros/rolling/include/rclcpp/logging.hpp:970:5: note: expanded from macro 'RCLCPP_WARN'
    RCUTILS_LOG_WARN_NAMED( \
    ^
/opt/ros/rolling/include/rcutils/logging_macros.h:747:3: note: expanded from macro 'RCUTILS_LOG_WARN_NAMED'
  RCUTILS_LOG_COND_NAMED( \
  ^
/opt/ros/rolling/include/rcutils/logging_macros.h:68:5: note: expanded from macro 'RCUTILS_LOG_COND_NAMED'
    RCUTILS_LOGGING_AUTOINIT; \
    ^
/opt/ros/rolling/include/rcutils/logging.h:531:39: note: expanded from macro 'RCUTILS_LOGGING_AUTOINIT'
        RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str); \
                                      ^

Feature request

This might not be feasible but I was trying to use this clang-tidy config and it the logging macros create a ton of warnings, not just this one. It would be really nice if we could find some way to replace the macros in RCLCPP with functions. Many of the errors in clang-tidy are because these expand into code from the c libraries. Another example is there are some c-style casts in these macros.

---
Checks:          '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm*'
WarningsAsErrors: ''
HeaderFilterRegex: ''
FormatStyle:     none

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the cppcoreguidelines-pro-bounds-array-to-pointer-decay warning with a RCLCPP_* macro, then trace the expansion through rclcpp/logging.hpp, rcutils/logging_macros.h, and rcutils/logging.h. Compare the macro expansions with the supplied clang-tidy configuration; done means the logging macros no longer produce these warnings when checked.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.