Skip to content

Commit

Permalink
suppress clang-tidy [google-explicit-constructor] in some cases where…
Browse files Browse the repository at this point in the history
… it is a false-positive

Signed-off-by: William Woodall <william@osrfoundation.org>
  • Loading branch information
wjwwood committed Sep 23, 2021
1 parent 28a7a8a commit eb6bf7e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
6 changes: 6 additions & 0 deletions rclcpp/include/rclcpp/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ struct FutureAndRequestId
{}

/// Allow implicit conversions to `std::future` by reference.
// intentionally allow implicit conversions
// NOLINTNEXTLINE(google-explicit-constructor)
operator FutureT &() {return this->future;}

/// Deprecated, use the `future` member variable instead.
Expand All @@ -69,6 +71,8 @@ struct FutureAndRequestId
* \deprecated
*/
[[deprecated("FutureAndRequestId: use .future instead of an implicit conversion")]]
// intentionally allow implicit conversions
// NOLINTNEXTLINE(google-explicit-constructor)
operator FutureT() {return this->future;}

// delegate future like methods in the std::future impl_
Expand Down Expand Up @@ -284,6 +288,8 @@ class Client : public ClientBase
*/
[[deprecated(
"FutureAndRequestId: use .future.share() instead of an implicit conversion")]]
// intentionally allow implicit conversions
// NOLINTNEXTLINE(google-explicit-constructor)
operator SharedFuture() {return this->future.share();}

// delegate future like methods in the std::future impl_
Expand Down
10 changes: 8 additions & 2 deletions rclcpp/include/rclcpp/duration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ class RCLCPP_PUBLIC Duration
// This constructor matches any std::chrono value other than nanoseconds
// intentionally not using explicit to create a conversion constructor
template<class Rep, class Period>
// intentionally allow implicit conversions
// cppcheck-suppress noExplicitConstructor
Duration(const std::chrono::duration<Rep, Period> & duration) // NOLINT(runtime/explicit)
// NOLINTNEXTLINE(runtime/explicit, google-explicit-constructor)
Duration(const std::chrono::duration<Rep, Period> & duration)
: Duration(std::chrono::duration_cast<std::chrono::nanoseconds>(duration))
{}

// intentionally allow implicit conversions
// cppcheck-suppress noExplicitConstructor
Duration(const builtin_interfaces::msg::Duration & duration_msg); // NOLINT(runtime/explicit)
// NOLINTNEXTLINE(runtime/explicit, google-explicit-constructor)
Duration(const builtin_interfaces::msg::Duration & duration_msg);

/// Time constructor
/**
Expand All @@ -69,6 +73,8 @@ class RCLCPP_PUBLIC Duration

virtual ~Duration() = default;

// intentionally allow implicit conversions
// NOLINTNEXTLINE(google-explicit-constructor)
operator builtin_interfaces::msg::Duration() const;

// cppcheck-suppress operatorEq // this is a false positive from cppcheck
Expand Down
4 changes: 3 additions & 1 deletion rclcpp/include/rclcpp/loaned_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ class LoanedMessage
: LoanedMessage(*pub, *allocator)
{}

/// Move semantic for RVO
/// Move constructor to support RVO.
// move constructors should not be explicit
// NOLINTNEXTLINE(google-explicit-constructor)
LoanedMessage(LoanedMessage<MessageT> && other)
: pub_(std::move(other.pub_)),
message_(std::move(other.message_)),
Expand Down
4 changes: 3 additions & 1 deletion rclcpp/include/rclcpp/message_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class RCLCPP_PUBLIC MessageInfo
/**
* \param[in] rmw_message_info message info to initialize the class
*/
// intentionally allow implicit conversions
// cppcheck-suppress noExplicitConstructor
MessageInfo(const rmw_message_info_t & rmw_message_info); // NOLINT(runtime/explicit)
// NOLINTNEXTLINE(runtime/explicit, google-explicit-constructor)
MessageInfo(const rmw_message_info_t & rmw_message_info);

virtual ~MessageInfo();

Expand Down
4 changes: 3 additions & 1 deletion rclcpp/include/rclcpp/qos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ class RCLCPP_PUBLIC QoS
* with a Publisher, or how many messages can be queued before being replaced
* by a Subscription.
*/
// intentionally allow implicit conversions
// cppcheck-suppress noExplicitConstructor
QoS(size_t history_depth); // NOLINT(runtime/explicit): conversion constructor
// NOLINTNEXTLINE(runtime/explicit, google-explicit-constructor)
QoS(size_t history_depth);

/// Return the rmw qos profile.
rmw_qos_profile_t &
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/include/rclcpp/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class Time
* \throws std::runtime_error if seconds are negative
*/
RCLCPP_PUBLIC
// intentionally allow implicit conversions
// cppcheck-suppress noExplicitConstructor
// NOLINTNEXTLINE(google-explicit-constructor)
Time(
const builtin_interfaces::msg::Time & time_msg,
rcl_clock_type_t clock_type = RCL_ROS_TIME);
Expand All @@ -81,6 +84,8 @@ class Time

/// Return a builtin_interfaces::msg::Time object based
RCLCPP_PUBLIC
// intentionally allow implicit conversions
// NOLINTNEXTLINE(google-explicit-constructor)
operator builtin_interfaces::msg::Time() const;

/**
Expand Down

0 comments on commit eb6bf7e

Please sign in to comment.