From dd19f1342bf435af6d02155365375d5f7a9dfc64 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Mon, 23 Nov 2026 21:26:18 +0200 Subject: [PATCH 1/5] assert: replace std::function-based overloads with a constrained template The 'std::function' checker overloads are ambiguous with 'assert(bool)' in Objective-C++ where blocks are enabled: lambdas returning bool become implicitly convertible to a block pointer, which is in turn implicitly convertible to bool. Replace both 'std::function' checker overloads with a single constrained template that accepts anything invocable as 'bool', and remove the generic 'std::function' non-emptiness overloads: call sites asserting a std::function object for non-emptiness now compare with 'nullptr' explicitly. Blocks are neither required nor supported with assert(); this change simply makes overloading well-defined in all translation unit flavors. --- src/utki/debug.hpp | 54 +++++++++------------------------------- tests/unit/src/debug.cpp | 42 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/utki/debug.hpp b/src/utki/debug.hpp index b6f2f268..a9d02378 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" @@ -293,13 +294,15 @@ inline void assert( * @brief Assert that condion is true. * In debug build this function invokes assert_always(). * In non-debug build this fuction does nothing. - * @param condition_checker - function which checks for condition and returns its boolean value. + * @param condition_checker - callable object (e.g. a lambda) which checks for condition + * and returns its boolean value. The checker is invoked only in debug builds. * @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. */ #ifdef DEBUG +template , int> = 0> inline void assert( - const std::function& condition_checker, + const checker_type& condition_checker, const std::function& print, const utki::source_location& source_location # if CFG_CPP >= 20 @@ -314,8 +317,9 @@ inline void assert( ); } #else +template , int> = 0> inline void assert( - const std::function&, + const checker_type&, const std::function&, const utki::source_location& # if CFG_CPP >= 20 @@ -351,11 +355,13 @@ inline void assert( * @brief Assert that condion is true. * In debug build this function invokes assert_always(). * In non-debug build this fuction does nothing. - * @param condition_checker - function which checks for condition and returns its boolean value. + * @param condition_checker - callable object (e.g. a lambda) which checks for condition + * and returns its boolean value. The checker is invoked only in debug builds. * @param source_location - location of the assert() invocation in the source code. */ +template , int> = 0> inline void assert( - const std::function& condition_checker, + const checker_type& condition_checker, const utki::source_location& source_location #if CFG_CPP >= 20 = std_source_location::current() @@ -364,7 +370,7 @@ inline void assert( { utki::assert( condition_checker, // - nullptr, + std::function{nullptr}, source_location ); } @@ -474,42 +480,6 @@ void assert( ); } -// std::function does not have implicit conversion to bool, so we need to define -// template overloads of the assert function for it - -template -void assert( - const std::function& p, - const std::function& print, - const utki::source_location& source_location -#if CFG_CPP >= 20 - = std_source_location::current() -#endif -) -{ - assert( - p != nullptr, // - print, - source_location - ); -} - -template -void assert( - const std::function& p, - const utki::source_location& source_location -#if CFG_CPP >= 20 - = std_source_location::current() -#endif -) -{ - assert( - p != nullptr, // - nullptr, - source_location - ); -} - } // namespace utki #ifdef DEBUG diff --git a/tests/unit/src/debug.cpp b/tests/unit/src/debug.cpp index 74ad99ea..616a7100 100644 --- a/tests/unit/src/debug.cpp +++ b/tests/unit/src/debug.cpp @@ -58,6 +58,48 @@ const tst::set set("debug", [](tst::suite& suite) { #endif }); + suite.add("assert_with_checker_captureless", []() { + const int b = 13; + utki::assert( + [&]() { // + return b == 13; + }, + SL + ); + utki::assert( + []() { // + return 13 == 13; + }, + SL + ); +#if CFG_CPP >= 20 + utki::assert( + [&]() { // + return b == 13; + } + ); + utki::assert([]() { + return 13 == 13; + }); +#endif + }); + + suite.add("assert_with_std_function_checker", []() { + // a std::function object binds to the checker overload and is invoked + int b = 13; + int calls = 0; + const std::function checker = [&]() { // + calls++; + return b == 13; + }; + utki::assert(checker, SL); + utki::assert(calls == 1, SL); +#if CFG_CPP >= 20 + utki::assert(checker); + utki::assert(calls == 2, SL); +#endif + }); + suite.add("assert_with_message", []() { int b = 13; utki::assert( From 16ad6967b9256faf725a222ccd6691478b530ed9 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Mon, 23 Nov 2026 21:44:48 +0200 Subject: [PATCH 2/5] assert: use a C++20 concept for the checker constraint when available Per review: guard the constraint with '#if CFG_CPP >= 20' and use a 'requires' clause (project-local concept 'assert_checker') in C++20, keeping the SFINAE form for C++17, following the pattern established in span.hpp. --- src/utki/debug.hpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/utki/debug.hpp b/src/utki/debug.hpp index a9d02378..b63c750a 100644 --- a/src/utki/debug.hpp +++ b/src/utki/debug.hpp @@ -290,6 +290,12 @@ inline void assert( #endif +// a type invocable with no arguments, producing a value convertible to bool +#if CFG_CPP >= 20 +template +concept assert_checker = std::is_invocable_r_v; +#endif + /** * @brief Assert that condion is true. * In debug build this function invokes assert_always(). @@ -300,7 +306,16 @@ inline void assert( * @param source_location - location of the assert() invocation in the source code. */ #ifdef DEBUG -template , int> = 0> +template < // + class checker_type +# if CFG_CPP < 20 + , + typename std::enable_if_t, int> = 0 +# endif + > +# if CFG_CPP >= 20 +requires assert_checker +# endif inline void assert( const checker_type& condition_checker, const std::function& print, @@ -317,7 +332,16 @@ inline void assert( ); } #else -template , int> = 0> +template < // + class checker_type +# if CFG_CPP < 20 + , + typename std::enable_if_t, int> = 0 +# endif + > +# if CFG_CPP >= 20 +requires assert_checker +# endif inline void assert( const checker_type&, const std::function&, @@ -359,7 +383,16 @@ inline void assert( * and returns its boolean value. The checker is invoked only in debug builds. * @param source_location - location of the assert() invocation in the source code. */ -template , int> = 0> +template < // + class checker_type +#if CFG_CPP < 20 + , + typename std::enable_if_t, int> = 0 +#endif + > +#if CFG_CPP >= 20 +requires assert_checker +#endif inline void assert( const checker_type& condition_checker, const utki::source_location& source_location From 6e72528ec94b87e8b56a7e0a296d45f66721b647 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Mon, 23 Nov 2026 21:44:48 +0200 Subject: [PATCH 3/5] ci: bump harness clargs/tst submodules to the nullptr-comparison fixes The harness builds clargs and tst against this branch's utki headers; the std::function-based assert() overloads are removed, so the harness copies need the matching '!= nullptr' call-site fixes (cppfw/clargs#21, cppfw/tst#27). --- tests/harness/clargs | 2 +- tests/harness/tst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/harness/clargs b/tests/harness/clargs index 24ecdc1f..26f70055 160000 --- a/tests/harness/clargs +++ b/tests/harness/clargs @@ -1 +1 @@ -Subproject commit 24ecdc1ffb03f01cb1bd7e66309a165eabf684f2 +Subproject commit 26f700559da08bac27d91ab53fb22908bfcab941 diff --git a/tests/harness/tst b/tests/harness/tst index 94871f70..8cfcd74f 160000 --- a/tests/harness/tst +++ b/tests/harness/tst @@ -1 +1 @@ -Subproject commit 94871f7015751b974db38c1d45976bcdc536b21d +Subproject commit 8cfcd74f1feb6e2726dbb882b4a3ca876452507a From fbc9d0b803b73b3b78dbd2c5ebf8e3760c3fe4e8 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Mon, 23 Nov 2026 21:57:07 +0200 Subject: [PATCH 4/5] ci: check out pinned submodule commits instead of remote branch tips The checkout action's 'remote_recursive' default (and the conan recipe's '--remote' flag) track the tips of the submodule branches instead of the pinned commits, so the harness clargs/tst copies did not pick up the nullptr-comparison fixes this branch requires. Use 'submodules: true' (pinned SHAs) everywhere and drop '--remote' from the conan recipe. The pinned SHAs are fetchable from the upstream repos while the corresponding PRs (cppfw/clargs#21, cppfw/tst#27) are open, as GitHub serves pull-request head commits. --- .github/workflows/ci.yml | 18 ++++++++++++++++++ build/conan/conanfile.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3749bf9e..b3f34183 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,8 @@ jobs: # keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: prepare debian package run: myci-deb-prepare.sh - name: install deps @@ -114,6 +116,8 @@ jobs: apt --quiet install --assume-yes devscripts equivs - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: prepare debian package run: myci-deb-prepare.sh - name: install deps @@ -147,6 +151,8 @@ jobs: install: myci locales git devscripts equivs - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: prepare debian package run: myci-deb-prepare.sh - name: install deps @@ -187,6 +193,8 @@ jobs: # keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: set PACKAGE_VERSION uses: myci-actions/export-env-var@main with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh)} @@ -258,6 +266,8 @@ jobs: # keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: set PACKAGE_VERSION uses: myci-actions/export-env-var@main with: {name: PACKAGE_VERSION, value: $(myci-deb-version.sh)} @@ -347,6 +357,8 @@ jobs: rm -rf /usr/local/bin/python3*-config - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: install clang-tidy and clang-format run: | brew install llvm @@ -388,6 +400,8 @@ jobs: steps: - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: add cppfw deb repo uses: myci-actions/add-deb-repo@main with: @@ -446,6 +460,8 @@ jobs: # key-server: https://gagis.hopto.org/repo/cppfw/pubkey.gpg - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: prepare pacman package run: myci-apply-version.sh build/msys2/PKGBUILD.in - name: build @@ -484,6 +500,8 @@ jobs: install: myci cmake git curl zip unzip tar nodejs - name: git clone uses: myci-actions/checkout@main + with: + submodules: true - name: install vcpkg run: | git clone https://github.com/microsoft/vcpkg.git vcpkg-installation diff --git a/build/conan/conanfile.py b/build/conan/conanfile.py index 16174d4a..13938624 100644 --- a/build/conan/conanfile.py +++ b/build/conan/conanfile.py @@ -42,7 +42,7 @@ def source(self): # shallow fetch commit git.fetch_commit(url=sources["url"], commit=sources['commit']) # shallow clone submodules - git.run("submodule update --init --remote --depth 1") + git.run("submodule update --init --depth 1") def build(self): if self.settings.os == "Emscripten": From 1fcf049399bdfaceb8aad82e927b0e4deda96a42 Mon Sep 17 00:00:00 2001 From: Ivan Gagis's Bot Date: Mon, 23 Nov 2026 22:47:26 +0200 Subject: [PATCH 5/5] tests: fix clang-format violation in debug test --- tests/unit/src/debug.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/unit/src/debug.cpp b/tests/unit/src/debug.cpp index 616a7100..448fbf4c 100644 --- a/tests/unit/src/debug.cpp +++ b/tests/unit/src/debug.cpp @@ -73,11 +73,9 @@ const tst::set set("debug", [](tst::suite& suite) { SL ); #if CFG_CPP >= 20 - utki::assert( - [&]() { // - return b == 13; - } - ); + utki::assert([&]() { // + return b == 13; + }); utki::assert([]() { return 13 == 13; });