fix(resolve): nine more C++ edge cases in the Rust resolver

Merged
BO
3d ago
+498-68

Nine C++ cases the Rust resolver got wrong now link correctly; each was reproduced by a test that fails without its fix. They are the review findings on #497 that were left unchanged, plus restricting object creation to the caller's include closure.

CaseBeforeNow
using Ptr = Widget*; Ptr p(0);counted as constructing a Widgetno construction edge
class nested in a function-local classvisible from other functionslocal to its function
class in an included .cc filenot the includer'sthe includer's
two headers declaring one classcreation could take eithertakes the one in its include closure
using Base<T>::foo; in a nested classcounted as the outer class'souter class's foo() goes to the free function
NULL as an overload argumenttreated as nullptran integer zero
a header's unnamed namespaceevery file'sits includers' only; a comment before a #define no longer hides a span
const int FOO_BAR = 1;FOO_BAR blanked as an annotationleft alone
n * FOO_BAR::VALUEFOO_BAR blankedleft alone

Extraction's TypeScript passes already left the last two alone; only the Rust port was wrong.

Checked, not changed. A string literal passed to a const void* overload ahead of a std::string one already picks the const void*: the test passes with my candidate fix disabled, so I dropped the fix and kept the test as a pin. The aggregate-binding finding is a feature request, not a defect.

Proof. __tests__/cpp-resolver-edge-cases.test.ts (10 tests) plus Rust unit tests in cpp_annotations.rs and cpp_translation_unit.rs. Mutation checks (fix disabled, kernel rebuilt) failed the header-namespace test; the other repros failed on the base commit. On this head: full suite 720 files / 9060 tests pass, cargo clippy --release --lib -- -D warnings, cargo test --release --lib (77 passed), tsc --noEmit, check:agent-docs and check:kernel-rules clean. Precision: json 11/11 absent and 7/7 present held; jq has no assertions (0/0). Kernel goldens unchanged.

README. Checked the "About this fork" rows and the 110/120/122/153-157 rows; row 157 (object creation and includes) gained one sentence. No number the README quotes moved.

Not covered: reporting any of this upstream.


Summary by cubic

Fixes C++ edge cases in the Rust resolver so links land on the right target; each is reproduced by a test that fails without its fix, and they complete the review findings from #497.

  • using Ptr = Widget*; Ptr p(0); no longer counts as constructing a Widget, including through a chain of aliases (using Ptr2 = Ptr;) and a global-qualified one (using Ptr3 = ::Ptr;); an alias's text is read with comments masked.
  • A class nested in a function-local class is local to that function, and an unnamed namespace in a header belongs only to that header's includers.
  • A class declared in an included .cc file is the includer's, and of two headers declaring one class, creation takes the one in its include closure.
  • A using Base<T>::foo; in a nested class no longer counts as the outer class's, including when the class's first line also opens a namespace.
  • NULL is treated as an integer zero when choosing an overload.
  • Annotation blanking leaves const int FOO_BAR = 1; and n * FOO_BAR::VALUE alone, but still blanks a macro after a name that follows a const-qualified type (int const value_ GUARDED_BY(mu_);); the Rust port and extraction now agree.

Not a defect: a string literal already converts to const void* ahead of a std::string overload, so its test pins behavior but ships no fix.

Summary by CodeRabbit

  • Bug Fixes
    • Improved C++ object creation and name resolution for included source files, duplicate class declarations, function-local nested classes, inherited using declarations, pointer and reference aliases, and unnamed namespaces.
    • Corrected overload selection for NULL and string literals.
    • Improved annotation handling for pointer and declarator expressions, including const- and volatile-qualified types.
  • Documentation
    • Clarified how included source files and duplicate declarations across headers affect C++ object creation.