Skip to content

assert: replace std::function-based overloads with a constrained template - #34

Merged
igagis merged 5 commits into
cppfw:mainfrom
igagis-bot:fix/assert-invocable-checker
Nov 23, 2026
Merged

igagis merged 5 commits into
cppfw:mainfrom
igagis-bot:fix/assert-invocable-checker

Conversation

@igagis-bot

@igagis-bot igagis-bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #33.

Problem

assert(bool, ...) is ambiguous with the std::function<bool()> checker
overload in Objective-C++ translation units (blocks enabled, the default
on Darwin): a lambda returning bool is implicitly convertible both to
bool (via the lambda's operator()) and to a block pointer
((^bool)(void)), which is itself implicitly convertible to bool.
Both conversion sequences are user-defined, so the call is ambiguous:

error: ambiguous template specialization:
    'assert'
    candidate: 'void assert(std::function<bool()>, const source_location &)'
    candidate: 'void assert(bool, const source_location &)'

This breaks every monorepo TU that is compiled as ObjC++ and includes a
header with a lambda-condition assert (e.g. rasterimage/image_variant.hpp).

Approach

Notes

  • Blocks are neither required nor supported with assert(); this change
    only makes overloading well-defined in ObjC++ TUs.
  • All 118 lambda-condition asserts in the monorepo keep working; verified
    with a full monorepo build + test run (353 tests).
  • Runtime semantics verified: capturing and captureless lambdas are both
    invoked, laziness in non-DEBUG builds is preserved, failing checkers
    abort as before.
  • A std::function<bool()> object is still accepted (it is invocable as
    bool and binds to the checker template).

…late

The 'std::function<bool()>' 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<bool()>' checker overloads with a single
constrained template that accepts anything invocable as 'bool', and
remove the generic 'std::function<func_type>' 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.
igagis-bot pushed a commit to igagis-bot/monorepo that referenced this pull request Nov 23, 2026
… nullptr comparison

utki::assert() checker overloads replaced with a constrained template (cppfw/utki#34); the std::function-based overloads are removed, so call sites asserting a std::function object for non-emptiness compare with nullptr explicitly (cppfw/clargs#21, cppfw/tst#27, cppfw/cssom#9, cppfw/ruis#195).
Comment thread src/utki/debug.hpp Resolved
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.
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).
igagis-bot pushed a commit to igagis-bot/monorepo that referenced this pull request Nov 23, 2026
Follow-up to cppfw/utki#34 (review: C++20 concept constraint;
CI harness clargs/tst bumps).
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.
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.84%. Comparing base (def482f) to head (1fcf049).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #34      +/-   ##
==========================================
- Coverage   84.86%   84.84%   -0.02%     
==========================================
  Files          31       31              
  Lines        1559     1557       -2     
  Branches      384      384              
==========================================
- Hits         1323     1321       -2     
  Misses        174      174              
  Partials       62       62              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@igagis
igagis merged commit ec1c167 into cppfw:main Nov 23, 2026
30 checks passed
igagis added a commit to cppfw/monorepo that referenced this pull request Nov 23, 2026
* fix CI builds: install bison, enable vulkan WSI, bump submodules

- ci: install bison on all platforms:
    - linux: add bison to the apt build tools (pre-installed, made explicit)
    - macos/ios: brew install bison (the pre-installed bison is too old and
      does not understand the %language directive used by tml.y)
    - windows: install bison from the pre-installed MSYS2 and add its bin
      directory to the PATH (bison is not pre-installed at all)
- vcpkg: enable the xlib and wayland features of vulkan-loader on linux, so
  that the vcpkg-provided loader exports vkCreateXlibSurfaceKHR and
  vkCreateWaylandSurfaceKHR (they are needed to link the gtk-4/xorg/wayland
  applications against the loader)
- ci: add the libx11-dev, libwayland-dev and libxkbcommon-dev packages to
  the linux build deps (needed to build vulkan-loader with the WSI features)
- repos/utki: bump to fix utki::assert() ambiguity for lambdas in
  Objective-C++ (broke the ios build)
- repos/ruis-render-vulkan: bump to fix C4244 narrowing conversion
  warnings on 32-bit (Win32) targets (broke the windows win32 build)

* fix macos/ios ci: force-link brew bison (keg-only, shadowed by /usr/bin/bison 2.3)

Homebrew installs bison keg-only because macOS already ships
/usr/bin/bison (2.3 from 2006, which does not support the %language
directive used by tml.y). Installing the bottle therefore did not
put a modern bison on the PATH and the tml-bnf generation failed.
Force-link the keg so that /opt/homebrew/bin/bison shadows the
system one.

* bump tml (skip tml-bnf on ios, fix bison 3.x yynerrs_ warning), drop bison from ios ci

tml-bnf is now ios-excluded (it is a development / testing aid), so the
ios job no longer needs bison. the tml bump also fixes the
-Wunused-but-set-variable error that bison 3.x generated code hits under
warnings-as-errors on the other platforms.

* fix vcpkg manifest: keep vulkan on all platforms

the previous commit mistakenly constrained the vulkan dependency to
'osx | ios', which removed it from the windows and linux vcpkg plans
(vulkan was intentionally unconstrained: 'needed on all platforms').
windows and linux get vulkan again; the linux-only vulkan-loader entry
merges its xlib / wayland features into the same loader build (verified:
vcpkg resolves vulkan-loader[core,xlib,wayland]).

* bump utki: scalar assert conditions (windows C2665 regression)

* ci: add 60-minute job timeout

a hung runner (observed on macos-latest, where a job stayed in_progress
for more than 3 hours) otherwise blocks the pull request indefinitely.

* ci: raise macos job timeout to 90 minutes

the full build on a macos runner takes about 55 minutes (plus configure),
which is too close to the 60-minute timeout: even healthy runs got
cancelled at the timeout.

* ci(linux): cap build parallelism at 4 jobs

The build presets use 'jobs: 0', which makes CMake invoke 'gmake -j'
(unlimited parallel jobs). On the 4-vCPU/15Gi linux runners this spawns
dozens of concurrent cc1plus processes (each ~300-700MB), exhausting
RAM+swap; the OOM killer kills the runner VM mid-build ('The runner has
received a shutdown signal' + 'Killed signal terminated program cc1plus').

Pass an explicit --parallel 4 (matching the runner's vCPU count) to the
build and test steps. This takes precedence over the preset's jobs
property and keeps peak build memory well within the runner's RAM.

* ci: per review - nproc parallelism, libvulkan-dev on linux, no bison on macos/windows

- linux: --parallel $(nproc) instead of a hardcoded number (a bare
  --parallel is equivalent to the preset's jobs: 0, which makes CMake
  pass a bare -j to gmake = unlimited jobs = OOM on the runner;
  verified with CMake 4.2.3)
- linux: use the system libvulkan-dev (its loader exports the WSI
  surface entry points) instead of the vcpkg vulkan-loader[xlib,wayland]
  hack; the vcpkg vulkan dependency is now !linux so find_package(Vulkan)
  falls back to the system loader. macos / ios keep the vcpkg vulkan
  port (runtime ICD is MoltenVK on those runners).
- macos / windows: no bison installation anymore - the tml-bnf build is
  gated to linux only (see tml PR cppfw/tml#49); once that PR is merged,
  the tml submodule pointer in this PR will be updated.

* bump tml: gate tml-bnf build to linux only (cppfw/tml#49, 4bd61fd)

* bump tml: 6ce0bd5 (LINUX platform variable for the tml-bnf gate)

* bump tml: 9fc2a9c (read yynerrs_ instead of pragma)

* bump tml to cppfw/tml main: tml-bnf linux-only gate + bison 3.x fixes (cppfw/tml#49 merged)

* bump tml to cppfw/tml main (a6925df, includes #50), ruis-render-vulkan to merged #4 (e6b74bc)

* bump utki, clargs, tst, cssom, ruis: assert std::function objects via nullptr comparison

utki::assert() checker overloads replaced with a constrained template (cppfw/utki#34); the std::function-based overloads are removed, so call sites asserting a std::function object for non-emptiness compare with nullptr explicitly (cppfw/clargs#21, cppfw/tst#27, cppfw/cssom#9, cppfw/ruis#195).

* bump utki: concepts guard + harness submodule fixes

Follow-up to cppfw/utki#34 (review: C++20 concept constraint;
CI harness clargs/tst bumps).

* bump utki to cppfw/utki#34 head (fbc9d0b)

* ci: bound macosx/ios build parallelism to hw.ncpu (preset jobs:0 = unlimited -> swap thrash on 16Gi runners)

* ci: bound windows build parallelism to NUMBER_OF_PROCESSORS (same jobs:0 unbounded issue)

* bump utki/clargs/tst/cssom/ruis to merged heads (assert fix series merged: utki#34 ec1c167, clargs#21, tst#27, cssom#9, ruis#195)

---------

Co-authored-by: Ivan Gagis's Bot <igagis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants