From 05b17e0f21cf265772b009974b663cffb71897e2 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Mon, 23 Nov 2026 00:59:27 +0200 Subject: [PATCH] fix(debug): resolve ambiguous assert() for lambdas on AppleClang Passing a capturing lambda to utki::assert() is ambiguous on AppleClang: it considers both the assert(bool, source_location) and the assert(const std::function&, source_location) overloads viable (it treats the lambda as convertible to bool), so overload resolution fails. GCC/Clang/MSVC do not consider the bool overload viable for a lambda, so the ambiguity only surfaces on AppleClang (iOS). Add a constrained template overload that matches callables whose result converts to bool. It is an exact match, so it is preferred over the bool overload on every compiler. It excludes pointers (which have dedicated overloads) and non-bool-convertible callables such as std::function. The callable is invoked only in DEBUG builds to preserve the existing no-op behavior in release builds. --- src/utki/debug.hpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/utki/debug.hpp b/src/utki/debug.hpp index b6f2f268..5645ea0b 100644 --- a/src/utki/debug.hpp +++ b/src/utki/debug.hpp @@ -32,6 +32,8 @@ SOFTWARE. #include #include #include +#include +#include #include "config.hpp" #include "log.hpp" @@ -369,6 +371,38 @@ inline void assert( ); } +// A callable object (e.g. a capturing lambda) whose result converts to bool is +// a lazy condition checker. Provide a dedicated overload for it so that it is +// preferred over the plain `bool` overload. Some compilers (notably AppleClang) +// incorrectly consider the `bool` overload a viable candidate for a lambda +// argument (treating the lambda as convertible to bool), which makes the call +// to assert() ambiguous. The constraint excludes pointers (which have their own +// overloads) and callables that do not return a bool-convertible type (such as +// std::function), which are handled by the std::function overload. +template < + typename condition_checker_type, + typename = std::enable_if_t< + std::is_invocable_v + && std::is_convertible_v, bool> + && !std::is_pointer_v>>> +inline void assert( + condition_checker_type&& condition_checker, + const utki::source_location& source_location +#if CFG_CPP >= 20 + = std_source_location::current() +#endif +) +{ +# ifdef DEBUG + const bool condition = static_cast( + std::invoke(std::forward(condition_checker)) + ); + utki::assert(condition, source_location); +#else + (void)condition_checker; +#endif +} + // MSVC compiler gives warning about implicit conversion of pointer to bool, // so define template overloads of the assert for that