From fdf647bb757759bc13da7cc38260f19984d04801 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 9 Sep 2024 11:53:28 -0400 Subject: [PATCH] Use compiler-agnostic defines to silence warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit g++ emits warnings that it can't recognize the clang-specific diagnostic pragmas. They are replaced by the internal compiler-specific macros so that nothing is emitted when g++ is used. Signed-off-by: Jérémie Galarneau Change-Id: I543987a861d2322aa2ef3b7d631f280d2ac999bf --- src/common/macros.hpp | 4 ++++ src/common/reference.hpp | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/common/macros.hpp b/src/common/macros.hpp index f1d039a1f..31190f2ba 100644 --- a/src/common/macros.hpp +++ b/src/common/macros.hpp @@ -270,6 +270,8 @@ void *memmove(DestinationType *d, const SourceType *s, size_t n) = delete; #define DIAGNOSTIC_IGNORE_LOGICAL_OP #define DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES #define DIAGNOSTIC_IGNORE_INVALID_OFFSETOF +#define DIAGNOSTIC_IGNORE_INJECTED_CLASS_NAME \ + _Pragma("GCC diagnostic ignored \"-Winjected-class-name\"") _Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"") #else /* GCC */ @@ -285,6 +287,8 @@ _Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"") #define DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES #endif /* __GNUG__ && __GNUC__ >= 7 */ #define DIAGNOSTIC_IGNORE_INVALID_OFFSETOF _Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"") + +#define DIAGNOSTIC_IGNORE_INJECTED_CLASS_NAME #endif /* Used to make specific C++ functions to C code. */ diff --git a/src/common/reference.hpp b/src/common/reference.hpp index 15dac55b9..f8ba33fed 100644 --- a/src/common/reference.hpp +++ b/src/common/reference.hpp @@ -8,6 +8,8 @@ #ifndef LTTNG_REFERENCE_H #define LTTNG_REFERENCE_H +#include + #include #include @@ -76,12 +78,12 @@ private: return; } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Winjected-class-name" + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_INJECTED_CLASS_NAME static_assert(std::is_class::value, "CustomDeleter must define a 'deleter' callable class."); const typename CustomDeleter::deleter del; -#pragma clang diagnostic pop + DIAGNOSTIC_POP del(_value); release(); -- 2.34.1