1 Commits

Author SHA1 Message Date
Colby Mchenry 61cb4188a7 fix(cpp): a call or type name never links to what only another source file can see (#2538)
Name matching linked C and C++ names to declarations no other
translation unit can name: a class or alias a `.cc` file declares for
itself, its members, and what a source file's unnamed namespace
declares. In rocksdb, other test files' bare `Put(…)`, `Flush()` and
`dbfull()` reached column_family_test.cc's `ColumnFamilyTestBase`
thousands of times, and inlineskiplist.h's `Node*` receivers reached the
`Node` hash_linklist_rep.cc declares in `namespace { … }`.

- isVisibleAcrossFiles rejects such a candidate for a C or C++ ref
  (isCppTranslationUnitLocal), as it does a `static` C function: a type
  only source files declare; a member written inside such a class; an
  out-of-line member of a type the member's own file sees only source
  files declare (a scope its file sees no type of may be a namespace:
  fmt's posix-mock-test.cc defines posix-mock.h's `test::close` beside
  ostream-test.cc's own `struct test`); and, for the rest, what an
  unnamed namespace of a source file holds. An alias of the scope keeps
  the member, since the class may be declared anywhere.
- A source file's declarations are still seen by the file itself, by a
  file that includes it, and by a header it includes below them
  (rocksdb's version_set.cc includes version_set_sync_and_async.h after
  its `FilePicker` classes).
- The unnamed-namespace spans come from a scanner that skips comments,
  preprocessor lines (continued past a CRLF too) and string, character
  and raw string literals.
- The typed lookups (cppMethodOf, resolveMethodOnType) take the
  candidates the call's file can see first (cppVisibleFirst): rocksdb's
  db_stress_shared_state.h and two benchmark `.cc` files each declare a
  `SharedState`, and a call in db_stress_common.cc is the header's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 17:44:46 +00:00