Repository navigation
fix(cpp): a smart pointer's held class lacking a method gets no edge only when its bases are known - #2530
Merged
Conversation
…only when its bases are known matchCppHeldTypeCall (#2440) returned null (no edge) for a `->` call on a `std::unique_ptr`/`std::shared_ptr`/`std::optional` whose held class lacks the method, unless that class is a class template. #2493 found the gap in the same rule for raw pointers and values: a base the index can't link may declare the method. protobuf's `class FlatAllocator : public decltype(ApplyTypeList<FlatAllocatorImpl>(…))` has no extends edge to `FlatAllocatorImpl`, and rocksdb's `WritePreparedTxnDB` derives from an alias each `#if` arm declares differently. Both paths now share one verdict, cppLacksMethod: no class template, and cppBasesKnown (every base on the way is linked to a class, or is a library type). Otherwise the call goes 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
Follow-up to #2493. A
->call on astd::unique_ptr/std::shared_ptr/std::optionalwhose held class has no method of that name (own or inherited) now gets no edge only when the class's bases are all known — the same rule #2493 applies to raw pointers, values and references. When a base on the way is one the index doesn't link, the call goes on as before.Why
matchCppHeldTypeCall(#2440) returned null for a held class lacking the method unless it was a class template. #2493 measured the gap in that rule on the raw-pointer path: a base the index can't link may declare the method.class FlatAllocator : public decltype(ApplyTypeList<FlatAllocatorImpl>(…))has no extends edge toFlatAllocatorImpl, so 95 rightalloc.PlanArray(…)→FlatAllocatorImpl::PlanArrayedges would have been dropped.WritePreparedTxnDB : public WritePreparedTxnDBBase, an alias each#if USE_COROUTINESarm declares differently.What changed
cppLacksMethod(cls): not a class template, andcppBasesKnown(cls)(every base each declaration writes, at every level, is linked by an extends edge to a class or is a library type such asstd::runtime_error).matchCppHeldTypeCallandmatchCppDeclaredTypeCallboth use it, so the two paths can't drift apart.->call on a smart pointer or optional reaches the type it holds #2440's[Unreleased]bullet now states the final rule. Neither fix(cpp): a->call on a smart pointer or optional reaches the type it holds #2440 nor fix(cpp): a call on a declared pointer, value or reference reaches the class its type names, not a namesake #2493 has shipped (latest release is 1.6.2), so a separate bullet would describe a change no user saw.Validation
Main
80e4b459vs this branch, full index of each repo (kernel included), dumps compared by natural keys:A probe on the held path explains why: rocksdb has 13,832 held-type calls whose class the lookup finds; 13,829 find the method, 2 are class templates, and the 1 remaining class has fully known bases. protobuf: 248, all find the method. So on these repos the change guards a shape they don't hit through smart pointers; it matters where a held class derives from a
decltype(…)or#if-varying alias, as the test pins. No CPU run: the new check runs only when the method was not found (3 rocksdb calls).Tests
__tests__/cpp-smart-pointer-receiver.test.ts: a heldstd::unique_ptr<internal::FlatAllocator>&whose class derives from adecltype(…)keeps main'sFlatAllocatorImpl::PlanArrayedge. It fails with main's held-path line restored, and passes here.🤖 Generated with Claude Code