Repository navigation
fix(cpp): a receiver declared as a class template's member type, like SkipList<Key, Comparator>::Iterator, is that template's member - #2573
Merged
Conversation
… SkipList<Key, Comparator>::Iterator, is that template's member The declarator regex read a type as a name plus one template argument list, so `SkipList<Key, Comparator>::Iterator iter(&list);` was read from its last name alone and looked up from the calling function: leveldb's skip-list tests linked `iter.Valid()` to `leveldb::Iterator::Valid`, rocksdb's to `IteratorBase::Valid`, and rocksdb's SkipListRep iterators linked their `iter_` member's calls (`InlineSkipList<…>::Iterator iter_;`) to their own methods. The type is now read whole, `Outer<Args>::Member`, and C++ lookup finds the member in the class template. A library template's member read this way is a library type only as an iterator (`std::vector<int>::iterator`, never a project class named `iterator`). Others name another type that may be the project's (`std::vector<Slice>::value_type`, gmock's `typename std::tuple_element<N - 1, MatcherTuple>::type matcher`), so their calls go on as before. 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 that the #2569 A/B surfaced.
The C++ declarator regex read a declared type as a name plus one template argument list. So
SkipList<Key, Comparator>::Iterator iter(&list);couldn't be read whole: the match started atIterator, and C++ lookup from the calling function found a different class.iter.Valid(),Seek()andkey()linked toleveldb::Iterator.IteratorBase.SkipListRep::IteratorandLookaheadIteratorhold anInlineSkipList<const MemTableRep::KeyComparator&>::Iterator iter_;(andprev_). Theiriter_.Valid()calls linked to the enclosing iterator's own methods, which the code doesn't call.What changed:
Reading the type:
CPP_DECLARATOR_TYPEnow readsOuter<Args>::Memberas one type, so C++ lookup (cppClassWritten) finds the member in the class template. Declarations written withtypename, over two lines, through a pointer, and as data members are all covered.Library templates:
isCppLibraryTypecounts a member of a library template's specialization as a library type only when it is an iterator.std::vector<int>::iteratoris the library's, never a project class namediterator, which is what main linked.calls to. Other members name another type that may be the project's, so their calls go on as before:std::vector<Slice>::value_type;typename std::tuple_element<N - 1, MatcherTuple>::type matcher.The existing test "a std trait or member type names another type, maybe the project's" relies on this rule.
Validation
__tests__/cpp-template-member-types.test.ts(5 tests): 3 reproductions fail on main and pass here. 2 guards pass on both: a member aliasBaseHyperClockCache<Table>::Shard*, andstd::vector<Slice>::value_type.std::vector<int>::iteratortest;value_typetest and the existingcpp-library-type-receivertest.db/skiplist_test.ccmoved fromleveldb::Iterator::*toleveldb::SkipList::Iterator::*. All are correct.memtable/skiplist_test.ccmoved fromIteratorBasetoSkipList::Iterator;memtable/inlineskiplist_test.ccmoved fromIteratorBasetoInlineSkipList::Iterator;memtable/skiplistrep.ccmoved fromSkipListRep::IteratortoInlineSkipList::Iterator.tuple_element<…>::typematcher above). The rule restores it.🤖 Generated with Claude Code