Case 111: enumerable_thread_specific Lambda-Init Ambiguity¶
| Field | Value |
|---|---|
| Verdict | 🟡 COMPATIBLE_WITH_RISK |
| Category | Risk |
| Classification | Scenario — Ecosystem case study |
| Platforms | Linux, macOS |
| Flags | Bad practice |
Detected ChangeKinds |
overload_ambiguity_introduced |
| Source files | catalog/cases/case111_enumerable_thread_specific_lambda_ambiguity/ |
| Ecosystem | oneTBB |
| Related rules | constructor-overload-ambiguity |
| Subject | Template and generic-programming issues |
Category: Subtle source break / regression suite | Verdict: 🟡 COMPATIBLE_WITH_RISK (conditional source break, proven by source_smoke; see below)
What breaks¶
A second constructor overload is added — enumerable_thread_specific(int_factory_t)
(a function-pointer-typed factory). By itself this is a pure addition:
existing call sites that pass an int still resolve to the original
constructor. But consumer code patterns that previously had a single
viable conversion path can now become ambiguous, particularly with
brace-initialization or generic callable arguments. The risk is silent —
code that compiled before may compile to a different constructor against
the new headers, or stop compiling at unrelated call sites that infer
the wrong overload.
Why function-pointer instead of std::function? A realistic
example (such as oneTBB) would accept std::function<int()>, but pulling in
<functional> from libstdc++ 13 trips castxml/clang (__assume__
attribute in <bits/stl_bvector.h>), which would prevent the integration
test from ever running. A function-pointer typedef exhibits the same
overload-ambiguity risk for the purposes of this regression fixture.
Why this matters¶
Mirrors a documented oneTBB pain point: adding lambda-/functor-accepting constructor overloads to existing handle types introduced overload ambiguity in real downstream code. The pattern is repeatable across container-like types.
How abicheck catches it¶
overload_ambiguity_introduced (abicheck/compare/overload_ambiguity.py)
builds a concrete witness call for every (preexisting overload, new
overload) pair of the same callable, constructors included: same arity,
same implicit-object qualifiers, identical types at every other position,
and at least one position where both parameters are scalars
(arithmetic, enum, pointer). An empty braced argument {} converts to any
scalar by the identity conversion, so neither candidate is better and the
call is ambiguous. Here int and int_factory_t (a function pointer) are
both scalars, and the finding names the witness:
mylib::enumerable_thread_specific({}). Both header backends report it.
The break is real but consumer-conditional — ets(42) and every typed
argument still resolve; only a caller that writes ets({}) (or otherwise
passes {} there) stops compiling. So the default gate is
COMPATIBLE_WITH_RISK (exit 0), and ground_truth.json records the proven
source break separately in conditional_breaks (the same fact/gate split as
case186). A project that promises source compatibility for brace-initialized
calls can gate overload_ambiguity_introduced.
Out of scope for the witness: templates (ranking by deduction), variadics,
and reference/class-typed parameters, whose conversions rank differently.
The older ctor_overload_ambiguity_risk heuristic (a class crossing from one
to two non-explicit converting constructors) is independent and may also
appear.
Code diff¶
| v1 | v2 |
|---|---|
enumerable_thread_specific(int); |
same — plus a new overload |
| (no other ctors) | enumerable_thread_specific(int_factory_t); (typedef int (*int_factory_t)()) |
How to fix (as a library maintainer)¶
- Constrain the lambda-init overload with a SFINAE / concept that
excludes
int-convertible types. e.g.: This eliminates the ambiguity at the call site. - Or expose the lambda-init as a named factory
(
from_lambda(...)) rather than as an overloaded constructor.
References¶
- oneTBB issue tracker — overload ambiguity in
enumerable_thread_specificconstructor set.
Source files¶
CMakeLists.txtapp.cppv1.cppv1.hv2.cppv2.h
See also: Compatibility Catalog · All COMPATIBLE_WITH_RISK cases · Category: Risk · Ecosystem: oneTBB · Subject: Template and generic-programming issues.