From 7b98804e98a9f5f68242c47fcc85401a751031f6 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Mon, 23 Nov 2026 03:38:39 +0200 Subject: [PATCH 1/2] fix utki::assert() ambiguity for lambdas in Objective-C++ In Objective-C++ code (built with -fblocks), lambda closure types are implicitly convertible to bool. This made calls of the form utki::assert([]() { return true; }); ambiguous: both the bool overload and the condition_checker (std::function) overload were viable candidates. Convert the bool-taking overloads to templates constrained with SFINAE to exactly the bool type, so that they are only selected for actual bool arguments and lambdas keep binding to the condition_checker overload unambiguously. --- src/utki/debug.hpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/utki/debug.hpp b/src/utki/debug.hpp index b6f2f268..55bfd400 100644 --- a/src/utki/debug.hpp +++ b/src/utki/debug.hpp @@ -32,6 +32,7 @@ SOFTWARE. #include #include #include +#include #include "config.hpp" #include "log.hpp" @@ -258,9 +259,18 @@ inline void assert_always( * @param print - function providing information string to print in case the assertion fails. * @param source_location - location of the assert() invocation in the source code. */ +// The condition_type template parameter and the SFINAE constraint make sure this overload is only +// selected for arguments of type bool. This is important, because in Objective-C++ closure types +// (lambdas) are implicitly convertible to bool, in which case both this overload and the +// condition_checker overload would be viable candidates for a lambda argument, and the call would +// become ambiguous. #ifdef DEBUG +template < + class condition_type, + // NOLINTNEXTLINE(modernize-use-constraints, "requires-expressions require C++20, but this header must also compile with pre-C++20 standards") + class = std::enable_if_t, bool>>> inline void assert( - bool condition, + condition_type condition, const std::function& print, const utki::source_location& source_location # if CFG_CPP >= 20 @@ -277,8 +287,12 @@ inline void assert( #else +template < + class condition_type, + // NOLINTNEXTLINE(modernize-use-constraints, "requires-expressions require C++20, but this header must also compile with pre-C++20 standards") + class = std::enable_if_t, bool>>> inline void assert( - bool, + condition_type, const std::function&, const utki::source_location& # if CFG_CPP >= 20 @@ -332,8 +346,12 @@ inline void assert( * @param condition - condition to check for being true. * @param source_location - location of the assert() invocation in the source code. */ +template < + class condition_type, + // NOLINTNEXTLINE(modernize-use-constraints, "requires-expressions require C++20, but this header must also compile with pre-C++20 standards") + class = std::enable_if_t, bool>>> inline void assert( - bool condition, + condition_type condition, const utki::source_location& source_location #if CFG_CPP >= 20 = std_source_location::current() From 815f6de7ef0ee9e874fad140fac89a991c61ec56 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Mon, 23 Nov 2026 07:06:53 +0200 Subject: [PATCH 2/2] fix assert() SFINAE constraint: accept scalar conditions, not just bool the previous constraint (is_same_v, bool>) rejected scalar condition types other than bool (int, size_t, Win32 BOOL, ...), which used to convert implicitly to the bool parameter. this broke the windows build of ruisapp, where e.g. UnregisterClassW() returns BOOL: error C2665: 'utki::assert': no overloaded function could convert all the argument types the new constraint (!is_class_v>) accepts every scalar type while still excluding class types (lambdas, smart pointers, std::function), which have dedicated overloads. this also keeps the objective-c++ fix: in objective-c++ with -fblocks lambdas are implicitly convertible to bool (via a block pointer), and with the old non-template bool overload a lambda condition was ambiguous with the condition_checker overload. --- src/utki/debug.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utki/debug.hpp b/src/utki/debug.hpp index 55bfd400..7a8304ea 100644 --- a/src/utki/debug.hpp +++ b/src/utki/debug.hpp @@ -260,15 +260,15 @@ inline void assert_always( * @param source_location - location of the assert() invocation in the source code. */ // The condition_type template parameter and the SFINAE constraint make sure this overload is only -// selected for arguments of type bool. This is important, because in Objective-C++ closure types -// (lambdas) are implicitly convertible to bool, in which case both this overload and the -// condition_checker overload would be viable candidates for a lambda argument, and the call would -// become ambiguous. +// selected for scalar conditions (bool, integers, pointers, enums). Class types are excluded: +// lambdas, smart pointers and std::function have their own overloads, and in Objective-C++ +// lambdas are implicitly convertible to bool (via a block pointer), which would make the +// condition_checker overload ambiguous for them. #ifdef DEBUG template < class condition_type, // NOLINTNEXTLINE(modernize-use-constraints, "requires-expressions require C++20, but this header must also compile with pre-C++20 standards") - class = std::enable_if_t, bool>>> + class = std::enable_if_t>>> inline void assert( condition_type condition, const std::function& print, @@ -290,7 +290,7 @@ inline void assert( template < class condition_type, // NOLINTNEXTLINE(modernize-use-constraints, "requires-expressions require C++20, but this header must also compile with pre-C++20 standards") - class = std::enable_if_t, bool>>> + class = std::enable_if_t>>> inline void assert( condition_type, const std::function&, @@ -349,7 +349,7 @@ inline void assert( template < class condition_type, // NOLINTNEXTLINE(modernize-use-constraints, "requires-expressions require C++20, but this header must also compile with pre-C++20 standards") - class = std::enable_if_t, bool>>> + class = std::enable_if_t>>> inline void assert( condition_type condition, const utki::source_location& source_location