Files
codegraph/__tests__
Colby Mchenry 4a591aeee8 fix(cpp): a call to an overloaded free function, like protobuf's ParseWithLimit(limit, data, result), reaches the overload its arguments fit (#2612)
A C++ call to a function outside a class took whichever same-named
function the name strategies ranked first, by file and line proximity,
never by its arguments. Methods already picked their overload by argument
count, string literals and written argument types (cppOverloadFor);
functions never did. protobuf's `ParseWithLimit(limit, data, result)` on an
`int32_t result` reached the `int64_t&` overload beside the call, and
rocksdb's `NewLRUCache(cache_opts)` the overload taking a `size_t
capacity`.

Exact, qualified (global, exact, partial) and macro-namespace matching now
keep their choice of function, then let the call's arguments pick among its
overloads, the functions of its qualified name the call's file can see
(cppFunctionOverload, with cppOverloadFor's count-then-type fit; the
macro-namespace scorer breaks its ties by type). The choice stays on a tie.
- An overload only another source file sees (another `.cc` file's
  `static`, an unnamed namespace's) never competes. When the name strategy
  had picked such a function, which was then rejected, the call now links
  to the overload its file sees: leveldb's `GetLengthPrefixedSlice(&input,
  &key)` reached memtable.cc's static and linked nothing.
- A function hides a class of its name, so a call to a name both have
  reaches the function.
- Only C++ calls: protobuf's Rust FFI calls lost their `extern` targets to
  the C definitions when every language went through it.

Argument types read better too: a parameter named like the function it
belongs to, protobuf's `std::string u64(uint64_t u64)`, was read as the
function's own declarator, so `u64` looked like a `std::string`.

Validated on the cgstd kit against main (627018eb), every changed site
classified by argument count against both targets, ~100 type-decided sites
read by hand:
- leveldb: 5 calls linked that linked nothing.
- fmt: 283 retargeted (139 to an overload that takes that many arguments,
  110 by type, 34 multi-line or defaulted); fmt's `fill_n(it, …)` on an
  iterator of unknown type now takes the `basic_appender` overload, right
  for fmt's usual iterator.
- rocksdb: 101 linked, 1118 retargeted (720 by count, 339 by type).
- protobuf: 29 linked, 941 retargeted (372 by count, 558 by type), e.g. the
  compiler helpers' `QualifiedClassName(enum_, …)` reaching the
  `EnumDescriptor*` overload and `Namespace(d->file())` no longer calling
  itself.
- redis (C): byte-identical.
Full suite: 7188 passed, 0 failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 03:32:08 +00:00
..