From 4cc4e0e6823625ed10691f0853e9d8c05adb1b1d Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Tue, 21 Jan 2020 11:41:06 -0800 Subject: [PATCH] Deprecated is_initialized() The function was previously documented as being deprecated, but this change adds compiler warnings if it is used. Ignore compiler warnings where the function is being tested and change to the preferred usage elsewhere. Signed-off-by: Jacob Perron --- rclcpp/include/rclcpp/utilities.hpp | 1 + rclcpp/test/test_init.cpp | 14 ++++++++++++++ rclcpp/test/test_publisher.cpp | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/rclcpp/include/rclcpp/utilities.hpp b/rclcpp/include/rclcpp/utilities.hpp index 606636ed0a..6194aaaa69 100644 --- a/rclcpp/include/rclcpp/utilities.hpp +++ b/rclcpp/include/rclcpp/utilities.hpp @@ -154,6 +154,7 @@ ok(rclcpp::Context::SharedPtr context = nullptr); * \return true if the context is initialized, and false otherwise */ RCLCPP_PUBLIC +[[deprecated("use the function ok() instead, which has the same usage.")]] bool is_initialized(rclcpp::Context::SharedPtr context = nullptr); diff --git a/rclcpp/test/test_init.cpp b/rclcpp/test/test_init.cpp index 6e51ccd6c3..bee35f3992 100644 --- a/rclcpp/test/test_init.cpp +++ b/rclcpp/test/test_init.cpp @@ -17,6 +17,14 @@ #include "rclcpp/exceptions.hpp" #include "rclcpp/utilities.hpp" +#if !defined(_WIN32) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#else // !defined(_WIN32) +# pragma warning(push) +# pragma warning(disable: 4996) +#endif + TEST(TestInit, is_initialized) { EXPECT_FALSE(rclcpp::is_initialized()); @@ -50,3 +58,9 @@ TEST(TestInit, initialize_with_unknown_ros_args) { EXPECT_FALSE(rclcpp::is_initialized()); } + +#if !defined(_WIN32) +# pragma GCC diagnostic pop +#else // !defined(_WIN32) +# pragma warning(pop) +#endif diff --git a/rclcpp/test/test_publisher.cpp b/rclcpp/test/test_publisher.cpp index 6719197ce9..2fad5cd2ae 100644 --- a/rclcpp/test/test_publisher.cpp +++ b/rclcpp/test/test_publisher.cpp @@ -28,7 +28,7 @@ class TestPublisher : public ::testing::Test public: static void SetUpTestCase() { - if (!rclcpp::is_initialized()) { + if (!rclcpp::ok()) { rclcpp::init(0, nullptr); } }