Repository navigation
fix(cpp): an auto local holding a library container's iterator calls the element's method through -> - #2579
Merged
Conversation
…s the element's method through `->` `auto it = logs_.begin(); it->IsSyncing()` had no type for `it`: a call on a library container (`std::deque<LogWriterNumber>`) returned nothing the auto-local reader could use, so `->` calls on it were matched by the method's name. A standard or abseil container's `begin`/`end`/`find`/ `lower_bound`/`rbegin`/… now types as `<container>::iterator`, and a standard search (`std::lower_bound`, `std::find_if`, `std::next`, …) as the iterator it is given first; #2576's cppArrowTarget then reaches the container's element. The element is looked up where the container's type is written (the `auto` local's declared site, a data member's class), not where the call is: an element nested in another class (`vs->obsolete_files_.begin()`) finds that class's type, not a namesake visible at the call. A holder's type stays looked up at the call: from a pimpl member's header the lookup finds a namesake (protobuf's other `DescriptorIndex`) or nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
This is the follow-up left after #2576.
An
autolocal initialized with a library container's iterator had no type. rocksdb'sauto it = logs_.begin(); it->IsSyncing()is an example: the auto-local reader (cppExpressionType) had nothing for a call onstd::deque<LogWriterNumber>. So->calls on such locals were matched by the method's name alone.What changed:
Container members: a standard-library or abseil container's
begin/end/cbegin/rbegin/crbegin/find/lower_bound/upper_bound/… now types as<container>::iterator, with the right iterator kind.Searches: a standard search (
std::find,find_if,lower_bound,upper_bound,min_element,max_element,partition_point,adjacent_find,next,prev) types as the iterator it is given first.From there, fix(cpp): a
->call on a declared container iterator calls the element's method #2576'scppArrowTargetreaches the container's element.Where the element is looked up: where the container's type is written — the
autolocal's declared site, or a data member's class — not at the call. So an element nested in another class (vs->obsolete_files_.begin()) finds that class's type, not a namesake visible at the call.Smart pointers are unchanged: their held type is still looked up at the call. A first version moved holders to the declaration site too, and the A/B caught two problems with it:
Rep, which the header only declares, wasn't found from the header, so about 80 rocksdb calls dropped from 0.9 to 0.65–0.8;index_->AddFile(…)went toSimpleDescriptorDatabase::DescriptorIndex, a namesake visible from the header.A new test pins this.
Project containers keep what their own
begin()returns. A project class named like a library container (util::span) isn't taken for it.Validation
__tests__/cpp-auto-iterator-arrow.test.ts(6 tests): 4 fail on main and pass here. 2 guards pass on both: the projectspan, and the pimpl smart pointer.it->LargestUserKey()onsub_compact_states.rbegin()reachesSubcompactionState;to_it->Merge(…)on a copy ofpairs_.begin()reachesSeqnoTimePair;it->start()overintervals_reachesInterval, the same target main gives.calls on that type;it->data()/it->size()overoperand_listreachSlice.it->IsSyncing()andReleaseWriter()onlogs_.begin()keep their target, with confidence up from 0.7 to 0.9.it->get()over anabsl::flat_hash_set<Arena::UniquePtr<int>>and over one ofArena::Ptr<int>reachArena::UniquePtr::getandArena::Ptr::get;it->name(*this)fromstd::lower_bound(by_name_flat_.begin(), …)reachesFileEntry::name.it->extendee(*this)keeps its target, with confidence up from 0.7 to 0.9.Remaining, out of scope:
(*it)->m()/(*it).m()dereferences, andauto x = *c.begin(), which would needcppPointeeto dereference iterators;it->second.m()chains, which needstd::pairmembers.🤖 Generated with Claude Code