From 7a8606fb399d034e35deae366d798bdba71ef0a8 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Wed, 22 Jan 2020 14:11:58 -0500 Subject: [PATCH] Deprecated is_initialized() (#967) 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 606636e..6194aaa 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 6e51ccd..bee35f3 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 6719197..2fad5cd 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); } }