Skip to content

Commit b0fed74

Browse files
committed
Use central macro definition for deprecation suppression
1 parent d8e3824 commit b0fed74

9 files changed

Lines changed: 53 additions & 75 deletions

File tree

include/ur_client_library/helpers.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ static inline int sched_get_priority_max(int policy)
6666

6767
#endif // _WIN32
6868

69+
/*!
70+
* \file
71+
* \brief Portable helpers to temporarily silence deprecation diagnostics.
72+
*
73+
* Use \ref URCL_SILENCE_DEPRECATED_BEGIN before and \ref URCL_SILENCE_DEPRECATED_END after the
74+
* code that must call deprecated APIs (e.g. deprecated library methods implemented for backward
75+
* compatibility). Expands to nothing on unsupported compilers.
76+
*
77+
* Example:
78+
* \code
79+
* URCL_SILENCE_DEPRECATED_BEGIN
80+
* legacy_call();
81+
* URCL_SILENCE_DEPRECATED_END
82+
* \endcode
83+
*/
84+
85+
#if defined(_MSC_VER)
86+
# define URCL_SILENCE_DEPRECATED_BEGIN __pragma(warning(push)) __pragma(warning(disable : 4996))
87+
# define URCL_SILENCE_DEPRECATED_END __pragma(warning(pop))
88+
#elif defined(__GNUC__)
89+
# define URCL_SILENCE_DEPRECATED_BEGIN \
90+
_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
91+
# define URCL_SILENCE_DEPRECATED_END _Pragma("GCC diagnostic pop")
92+
#else
93+
# define URCL_SILENCE_DEPRECATED_BEGIN
94+
# define URCL_SILENCE_DEPRECATED_END
95+
#endif
96+
6997
namespace urcl
7098
{
7199
bool setFiFoScheduling(pthread_t& thread, const int priority);

src/control/motion_primitives.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
// POSSIBILITY OF SUCH DAMAGE.
2929
// -- END LICENSE BLOCK ------------------------------------------------
3030

31+
#include <ur_client_library/helpers.h>
3132
#include <ur_client_library/control/motion_primitives.h>
3233
#include <ur_client_library/log.h>
3334

3435
namespace urcl::control
3536
{
36-
#pragma GCC diagnostic push
37-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
37+
URCL_SILENCE_DEPRECATED_BEGIN
3838

3939
bool MotionPrimitive::validate() const
4040
{
@@ -164,7 +164,6 @@ void MoveJPrimitive::setTarget(const MotionTarget& target)
164164
if constexpr (std::is_same_v<T, urcl::Pose>)
165165
{
166166
type = MotionType::MOVEJ_POSE;
167-
168167
target_joint_configuration.fill(0);
169168
}
170169
else if constexpr (std::is_same_v<T, Q>)
@@ -426,6 +425,7 @@ void OptimoveLPrimitive::setTarget(const MotionTarget& target)
426425
},
427426
target);
428427
}
429-
#pragma GCC diagnostic pop
428+
429+
URCL_SILENCE_DEPRECATED_END
430430

431431
} // namespace urcl::control

src/ur/ur_driver.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "ur_client_library/rtde/rtde_client.h"
3636
#include "ur_client_library/control/script_reader.h"
3737
#include "ur_client_library/exceptions.h"
38-
#include "ur_client_library/helpers.h"
3938
#include "ur_client_library/primary/primary_parser.h"
4039
#include "ur_client_library/helpers.h"
4140
#include <memory>
@@ -188,13 +187,7 @@ void UrDriver::init(const UrDriverConfiguration& config)
188187
URCL_LOG_DEBUG("Initialization done");
189188
}
190189

191-
#ifdef __GNUC__
192-
# pragma GCC diagnostic push
193-
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
194-
#elif defined(_MSC_VER)
195-
# pragma warning(push)
196-
# pragma warning(disable : 4996)
197-
#endif
190+
URCL_SILENCE_DEPRECATED_BEGIN
198191
std::unique_ptr<rtde_interface::DataPackage> urcl::UrDriver::getDataPackage()
199192
{
200193
// This can take one of two values, 0ms or 100ms. The large timeout is for when the robot is commanding the control
@@ -204,11 +197,7 @@ std::unique_ptr<rtde_interface::DataPackage> urcl::UrDriver::getDataPackage()
204197

205198
return rtde_client_->getDataPackage(timeout);
206199
}
207-
#ifdef __GNUC__
208-
# pragma GCC diagnostic pop
209-
#elif defined(_MSC_VER)
210-
# pragma warning(pop)
211-
#endif
200+
URCL_SILENCE_DEPRECATED_END
212201

213202
bool UrDriver::getDataPackage(rtde_interface::DataPackage& data_package)
214203
{
@@ -708,20 +697,10 @@ void UrDriver::setKeepaliveCount(const uint32_t count)
708697
"set the "
709698
"read timeout in the write commands directly. This keepalive count will overwrite the timeout passed "
710699
"to the write functions.");
711-
// TODO: Remove 2027-05
712-
#ifdef _MSC_VER
713-
# pragma warning(push)
714-
# pragma warning(disable : 4996)
715-
#else
716-
# pragma GCC diagnostic push
717-
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
718-
#endif
700+
// TODO: Remove 2027-05
701+
URCL_SILENCE_DEPRECATED_BEGIN
719702
reverse_interface_->setKeepaliveCount(count);
720-
#ifdef _MSC_VER
721-
# pragma warning(pop)
722-
#else
723-
# pragma GCC diagnostic pop
724-
#endif
703+
URCL_SILENCE_DEPRECATED_END
725704
}
726705

727706
void UrDriver::resetRTDEClient(const std::vector<std::string>& output_recipe,

tests/test_primary_client.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ TEST_F(PrimaryClientTest, start_communication_succeeds)
103103

104104
TEST_F(PrimaryClientTest, add_and_remove_consumer)
105105
{
106-
#pragma GCC diagnostic push
107-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
106+
URCL_SILENCE_DEPRECATED_BEGIN
108107
auto calibration_consumer = std::make_shared<urcl::CalibrationChecker>("test");
109-
#pragma GCC diagnostic pop
108+
URCL_SILENCE_DEPRECATED_END
110109

111110
client_->addPrimaryConsumer(calibration_consumer);
112111

tests/test_reverse_interface.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <ur_client_library/control/reverse_interface.h>
3434
#include <ur_client_library/comm/tcp_socket.h>
3535
#include <ur_client_library/exceptions.h>
36+
#include "ur_client_library/helpers.h"
3637
#include "ur_client_library/log.h"
3738

3839
using namespace urcl;
@@ -484,19 +485,9 @@ TEST_F(ReverseInterfaceTest, deprecated_set_keep_alive_count)
484485

485486
// Test that it works to set the keepalive count using the deprecated function
486487
int keep_alive_count = 10;
487-
#ifdef _MSC_VER
488-
# pragma warning(push)
489-
# pragma warning(disable : 4996)
490-
#else
491-
# pragma GCC diagnostic push
492-
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
493-
#endif
488+
URCL_SILENCE_DEPRECATED_BEGIN
494489
reverse_interface_->setKeepaliveCount(keep_alive_count);
495-
#ifdef _MSC_VER
496-
# pragma warning(pop)
497-
#else
498-
# pragma GCC diagnostic pop
499-
#endif
490+
URCL_SILENCE_DEPRECATED_END
500491
int32_t expected_read_timeout = 20 * keep_alive_count;
501492

502493
urcl::vector6d_t pos = { 0, 0, 0, 0, 0, 0 };

tests/test_rtde_client.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
#include <iostream>
3838
#include "ur_client_library/comm/tcp_server.h"
3939
#include "ur_client_library/exceptions.h"
40+
#include "ur_client_library/helpers.h"
4041

4142
#include <ur_client_library/rtde/rtde_client.h>
4243
#include <ur_client_library/ur/version_information.h>
4344

4445
#include "fake_rtde_server.h"
45-
#include "ur_client_library/helpers.h"
4646
#include "ur_client_library/log.h"
4747

4848
using namespace urcl;
@@ -301,10 +301,9 @@ TEST_F(RTDEClientTest, get_data_package_w_background_deprecated)
301301

302302
// Test that we can receive a package and extract data from the received package
303303
const std::chrono::milliseconds read_timeout{ 100 };
304-
#pragma GCC diagnostic push
305-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
304+
URCL_SILENCE_DEPRECATED_BEGIN
306305
std::unique_ptr<rtde_interface::DataPackage> data_pkg = client_->getDataPackage(read_timeout);
307-
#pragma GCC diagnostic pop
306+
URCL_SILENCE_DEPRECATED_END
308307
if (data_pkg == nullptr)
309308
{
310309
std::cout << "Failed to get data package from robot" << std::endl;

tests/test_rtde_parser.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,9 @@ TEST(rtde_parser, test_deprecated_parse_method)
271271
std::vector<std::unique_ptr<rtde_interface::RTDEPackage>> products;
272272
{
273273
comm::BinParser bp(raw_data, sizeof(raw_data));
274-
#ifdef __GNUC__
275-
# pragma GCC diagnostic push
276-
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
277-
#elif defined(_MSC_VER)
278-
# pragma warning(push)
279-
# pragma warning(disable : 4996)
280-
#endif
274+
URCL_SILENCE_DEPRECATED_BEGIN
281275
parser.parse(bp, products);
282-
#ifdef __GNUC__
283-
# pragma GCC diagnostic pop
284-
#elif defined(_MSC_VER)
285-
# pragma warning(pop)
286-
#endif
276+
URCL_SILENCE_DEPRECATED_END
287277
}
288278

289279
EXPECT_EQ(products.size(), 1);

tests/test_tcp_socket.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@
3434
#include <cstddef>
3535
#include "test_utils.h"
3636

37-
// This file adds a test for a deprecated function. To avoid a compiler warning in CI (where we want
38-
// to treat warnings as errors) we suppress the warning inside this file.
39-
#ifdef _MSC_VER
40-
# pragma warning(disable : 4996)
41-
#else
42-
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
43-
#endif
4437
#include <ur_client_library/comm/tcp_socket.h>
4538
#include <ur_client_library/comm/tcp_server.h>
4639
#include "ur_client_library/types.h"
@@ -302,7 +295,9 @@ TEST_F(TCPSocketTest, connect_non_running_robot)
302295

303296
TEST_F(TCPSocketTest, test_deprecated_reconnection_time_interface)
304297
{
298+
URCL_SILENCE_DEPRECATED_BEGIN
305299
client_->setReconnectionTime(std::chrono::milliseconds(100));
300+
URCL_SILENCE_DEPRECATED_END
306301
EXPECT_TRUE(client_->setup(2));
307302
}
308303

tests/test_ur_driver.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ class UrDriverTest : public ::testing::Test
125125
TEST_F(UrDriverTest, read_non_existing_script_file)
126126
{
127127
const std::string non_existing_script_file = "";
128-
#pragma GCC diagnostic push
129-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
128+
URCL_SILENCE_DEPRECATED_BEGIN
130129
EXPECT_THROW(UrDriver::readScriptFile(non_existing_script_file), UrException);
131-
#pragma GCC diagnostic pop
130+
URCL_SILENCE_DEPRECATED_END
132131
}
133132

134133
TEST_F(UrDriverTest, read_existing_script_file)
@@ -145,11 +144,9 @@ TEST_F(UrDriverTest, read_existing_script_file)
145144
std::cout << "Failed to create temporary files" << std::endl;
146145
GTEST_FAIL();
147146
}
148-
#pragma GCC diagnostic push
149-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
147+
URCL_SILENCE_DEPRECATED_BEGIN
150148
EXPECT_NO_THROW(UrDriver::readScriptFile(existing_script_file));
151-
#pragma GCC diagnostic pop
152-
149+
URCL_SILENCE_DEPRECATED_END
153150
// clean up
154151
ofs.close();
155152
std::remove(existing_script_file);

0 commit comments

Comments
 (0)