From 902a576b73d40f6dd06b662d42c1be4ca5c19aaf Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 30 Mar 2022 12:32:26 +0100 Subject: [PATCH] NullCheckedInvocation: Disable Waddress warning When calling NullCheckedInvocation::invoke with a capture-less lambda, GCC 9.3 determines that the expression std::declval() != nullptr is well-formed, and uses the version of invoke containing a nullptr check. However, the compiler is also able to determine that this expression can never be false, and emits a warning. --- modules/juce_core/misc/juce_Functional.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/juce_core/misc/juce_Functional.h b/modules/juce_core/misc/juce_Functional.h index 142f5f9d3e..57e9929164 100644 --- a/modules/juce_core/misc/juce_Functional.h +++ b/modules/juce_core/misc/juce_Functional.h @@ -36,6 +36,9 @@ namespace detail template struct EqualityComparableToNullptr() != nullptr)>> : std::true_type {}; + + template + constexpr bool shouldCheckAgainstNullptr = EqualityComparableToNullptr::value; } // namespace detail #endif @@ -51,15 +54,19 @@ namespace detail struct NullCheckedInvocation { template ::value, int> = 0> + std::enable_if_t, int> = 0> static void invoke (Callable&& fn, Args&&... args) { + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Waddress") + if (fn != nullptr) fn (std::forward (args)...); + + JUCE_END_IGNORE_WARNINGS_GCC_LIKE } template ::value, int> = 0> + std::enable_if_t, int> = 0> static void invoke (Callable&& fn, Args&&... args) { fn (std::forward (args)...);