fix(resolve): nine more C++ edge cases in the Rust resolver
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.
| Case | Before | Now |
|---|---|---|
using Ptr = Widget*; Ptr p(0); | counted as constructing a Widget | no construction edge |
| class nested in a function-local class | visible from other functions | local to its function |
class in an included .cc file | not the includer's | the includer's |
| two headers declaring one class | creation could take either | takes the one in its include closure |
using Base<T>::foo; in a nested class | counted as the outer class's | outer class's foo() goes to the free function |
NULL as an overload argument | treated as nullptr | an integer zero |
| a header's unnamed namespace | every file's | its includers' only; a comment before a #define no longer hides a span |
const int FOO_BAR = 1; | FOO_BAR blanked as an annotation | left alone |
n * FOO_BAR::VALUE | FOO_BAR blanked | left 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 aWidget, 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
.ccfile 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. NULLis treated as an integer zero when choosing an overload.- Annotation blanking leaves
const int FOO_BAR = 1;andn * FOO_BAR::VALUEalone, 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
usingdeclarations, pointer and reference aliases, and unnamed namespaces. - Corrected overload selection for
NULLand string literals. - Improved annotation handling for pointer and declarator expressions, including const- and volatile-qualified types.
- Improved C++ object creation and name resolution for included source files, duplicate class declarations, function-local nested classes, inherited
- Documentation
- Clarified how included source files and duplicate declarations across headers affect C++ object creation.