fix(extraction): record instantiates for C++ stack/brace construction (#1035)#1049
Merged
Merged
Conversation
…#1035) `instantiates` edges came only from heap `new Calculator(0)` (a new_expression) and copy-init `Calculator c = Calculator(0)` (a call_expression). Stack direct-init `Calculator calc(0)` and brace-init `Widget w{1, 2}` parse as a `declaration` whose constructor arguments hang directly off the declarator as an argument_list / initializer_list — there is no call/new node — so the function-body walker saw no constructor invocation and emitted no edge. A function that built objects with the ordinary stack syntax looked like it didn't construct them, and the dependency was missing from impact / callers. In the body walker, a C++ `declaration` that is a stack/brace construction now reuses extractInstantiation (a declaration's `type` field IS the constructed class name, and extractInstantiation already strips template args / namespace and emits the `instantiates` ref). Gated by isCppStackConstruction, which requires BOTH a class-like type (type_identifier / template_type / qualified_identifier — so `int x(0)` and `auto z = …` are excluded) AND a declarator carrying args (argument_list / initializer_list — so default `Calculator c;` and the most-vexing-parse `Calculator c();` are excluded). The edge targets the class node, not the same-named constructor method. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Fixes #1035.
Problem
instantiatesedges came only from heapnew Calculator(0)(anew_expression) and copy-initCalculator c = Calculator(0)(acall_expression). Stack direct-initCalculator calc(0)and brace-initWidget w{1, 2}parse as adeclarationwhose constructor arguments hang directly off the declarator as anargument_list/initializer_list— there's no call/new node — so the function-body walker saw no constructor invocation and emitted no edge. A function that built objects with the ordinary stack syntax looked like it didn't construct them, and the dependency was missing from impact / callers.Fix
In the body walker, a C++
declarationthat is a stack/brace construction now reusesextractInstantiation(a declaration'stypefield is the constructed class name, andextractInstantiationalready strips template args / namespace and emits theinstantiatesref). Gated byisCppStackConstruction, which requires both:type(type_identifier/template_type/qualified_identifier) — soint x(0)(primitive) andauto z = …(handled via its owncall_expression) are excluded; andargument_list/initializer_list) — so default constructionCalculator c;and the most-vexing-parseCalculator c();(a function declaration) are excluded.The edge targets the class node, not the same-named constructor method. Template/namespace stripping is inherited:
std::vector<int> v(10)→vector,ns::Widget w(0)→Widget.Tests / verification
(#1035): 4 extraction (direct/brace-init emit the ref, template/namespace strip, negatives, multi-declarator) + 1 end-to-end resolution (instantiatesresolves to the class; heap still works; primitives/default don't).Out of scope
Copy-init
Calculator c = Calculator(0)records acallsedge to the constructor method rather thaninstantiatesto the class — defensible either way, and this issue is specifically about the stack syntax. Can be a follow-up if we want it normalized.🤖 Generated with Claude Code