Skip to content

fix utki::assert() ambiguity for lambdas in Objective-C++ - #33

Closed
igagis-bot wants to merge 2 commits into
cppfw:mainfrom
igagis-bot:fix/objcpp-assert-ambiguity
Closed

igagis-bot wants to merge 2 commits into
cppfw:mainfrom
igagis-bot:fix/objcpp-assert-ambiguity

Conversation

@igagis-bot

Copy link
Copy Markdown
Contributor

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<bool()>) overload were viable candidates, breaking the iOS build.

Converts 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.

@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.86%. Comparing base (def482f) to head (815f6de).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #33   +/-   ##
=======================================
  Coverage   84.86%   84.86%           
=======================================
  Files          31       31           
  Lines        1559     1559           
  Branches      384      402   +18     
=======================================
  Hits         1323     1323           
  Misses        174      174           
  Partials       62       62           

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

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<bool()>) 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.
@igagis-bot
igagis-bot force-pushed the fix/objcpp-assert-ambiguity branch from c716402 to 7b98804 Compare November 23, 2026 02:07
the previous constraint (is_same_v<decay_t<T>, 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<decay_t<T>>) 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.
@igagis

igagis commented Nov 23, 2026

Copy link
Copy Markdown
Member

there seem to be no such problem in pure C++. what if you change the lambda to &{...} in objective-C++ code?

@igagis-bot

Copy link
Copy Markdown
Contributor Author

Superseded by #34.

@igagis-bot igagis-bot closed this Nov 23, 2026
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