Skip to content

fix: ambiguous comparison between indexed accessor and cell reference#436

Merged
HDembinski merged 1 commit into
boostorg:developfrom
henryiii:fix-403-ambiguous-accessor-comparison
Jul 23, 2026
Merged

fix: ambiguous comparison between indexed accessor and cell reference#436
HDembinski merged 1 commit into
boostorg:developfrom
henryiii:fix-403-ambiguous-accessor-comparison

Conversation

@henryiii

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Fixes #403.

With the default storage, comparing two const accessors (as std::min_element/max_element do via libc++'s comparator) or an accessor with a cell reference failed to compile: the accessor's catch-all comparison templates and the mirrored friend operators of unlimited_storage::reference were equally good matches. The existing stdlib test did not catch this because it uses std::array<int> storage, where the cell reference is a plain int&.

  • Add the missing const to the accessor-vs-accessor comparison operators, so const contexts use them instead of falling into the catch-all template.
  • Constrain the generic operators in detail/operators.hpp to yield when the other operand's class handles the comparison with a member, extending the tie-breaker operator== already had (via new has_method_* detectors in detail/detect.hpp). The constraints only remove one side of a former ambiguity, so large_int and arithmetic operands are unaffected.
  • Add regression tests: the reported repro plus all six operators for accessor/accessor, accessor/reference in both directions, and accessor/int. They produce 20 compile errors without the fix.

Verified locally with Apple clang (C++14/17/20/2b, libc++) and gcc-16 (C++14/20, libstdc++); full CMake test suite passes.

Comparing two const accessors, or an accessor with a storage cell
reference, did not compile with the default storage: the accessor's
catch-all comparison templates and the mirrored friend operators of
unlimited_storage::reference were equally good matches.

Make the accessor-vs-accessor operators const so that standard
algorithms (which compare through const references) use them, and
constrain the generic operators in detail/operators.hpp to yield when
the other operand's class handles the comparison with a member, as
operator== already did.

Fixes boostorg#403

Assisted-by: ClaudeCode:claude-fable-5
@HDembinski
HDembinski merged commit ad57696 into boostorg:develop Jul 23, 2026
9 checks passed
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.

Build error on Mac OS Version 15 - Clang Version 16

2 participants