1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-18 00:54:19 +00:00

NullCheckedInvocation: Disable Waddress warning

When calling NullCheckedInvocation::invoke with a capture-less lambda,
GCC 9.3 determines that the expression
    std::declval<TheLambda>() != 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.
This commit is contained in:
reuk 2022-03-30 12:32:26 +01:00
parent d9c25ec17d
commit 902a576b73

View file

@ -36,6 +36,9 @@ namespace detail
template <typename T>
struct EqualityComparableToNullptr<T, Void<decltype (std::declval<T>() != nullptr)>>
: std::true_type {};
template <typename T>
constexpr bool shouldCheckAgainstNullptr = EqualityComparableToNullptr<T>::value;
} // namespace detail
#endif
@ -51,15 +54,19 @@ namespace detail
struct NullCheckedInvocation
{
template <typename Callable, typename... Args,
std::enable_if_t<detail::EqualityComparableToNullptr<Callable>::value, int> = 0>
std::enable_if_t<detail::shouldCheckAgainstNullptr<Callable>, int> = 0>
static void invoke (Callable&& fn, Args&&... args)
{
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Waddress")
if (fn != nullptr)
fn (std::forward<Args> (args)...);
JUCE_END_IGNORE_WARNINGS_GCC_LIKE
}
template <typename Callable, typename... Args,
std::enable_if_t<! detail::EqualityComparableToNullptr<Callable>::value, int> = 0>
std::enable_if_t<! detail::shouldCheckAgainstNullptr<Callable>, int> = 0>
static void invoke (Callable&& fn, Args&&... args)
{
fn (std::forward<Args> (args)...);