Repository navigation
fix(debug): resolve ambiguous assert() for lambdas on AppleClang - #32
Closed
igagis-bot wants to merge 1 commit into
Closed
igagis-bot wants to merge 1 commit into
igagis-bot wants to merge 1 commit into
Conversation
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<bool()>&, 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<void()>. The callable is invoked only in DEBUG builds to preserve the existing no-op behavior in release builds.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #32 +/- ##
==========================================
- Coverage 84.86% 84.85% -0.01%
==========================================
Files 31 31
Lines 1559 1558 -1
Branches 384 384
==========================================
- Hits 1323 1322 -1
Misses 174 174
Partials 62 62 ☔ View full report in Codecov by Harness. |
Contributor
Author
|
Superseded by #33: this PR only added a 2-arg (condition_lambda, SL) template overload, but the codebase also has 3-arg assert(condition, print, SL) call shapes where the same ObjC++ lambda-to-bool conversion makes the bool and std::function<bool()> overloads ambiguous. #33 constrains all three bool-taking overloads to exactly bool via SFINAE, covering every arity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The iOS CI build fails to compile
assert(lambda, SL)calls with:AppleClang (unlike GCC/Clang/MSVC) considers the
booloverload a viable candidate for acapturing lambda argument (it treats the lambda as convertible to
bool), so the call toassert()between thebooland thestd::function<bool()>overloads becomes ambiguous.The
assert(lambda, SL)lazy-condition pattern is used in ~116 call sites across manylibraries, so the failure surfaces in whichever translation unit is compiled first (e.g.
rasterimage/image_variant.hpp).Fix
Add a constrained template overload that matches callables whose result converts to
bool.It is an exact match, so it is preferred over the
booloverload on every compiler:The constraint:
shared_ptr/unique_ptr/ function pointers) on their existing overloads;std::function<void()>(and other non-boolcallables) on the existingstd::function<func_type>overload;DEBUGbuilds, preserving the existing no-op behavior in release builds.Verification
dbgbuild ofall(g++ 14): 138 targets, 0 errors.utki-tests: 327/327 pass.svgdom-tests: 51/51 pass (exercises 48assert(lambda, SL)sites at runtime).g++andclang++.