Skip to content

fix(extraction): record instantiates for C++ stack/brace construction (#1035)#1049

Merged
colbymchenry merged 1 commit into
mainfrom
fix/cpp-stack-allocation-instantiates-1035
Jun 29, 2026
Merged

fix(extraction): record instantiates for C++ stack/brace construction (#1035)#1049
colbymchenry merged 1 commit into
mainfrom
fix/cpp-stack-allocation-instantiates-1035

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

Fixes #1035.

Problem

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'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++ 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) (primitive) and auto z = … (handled via its own call_expression) are excluded; and
  • a declarator carrying constructor args (argument_list / initializer_list) — so default construction Calculator c; and the most-vexing-parse Calculator 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

  • 5 new tests under (#1035): 4 extraction (direct/brace-init emit the ref, template/namespace strip, negatives, multi-declarator) + 1 end-to-end resolution (instantiates resolves to the class; heap still works; primitives/default don't).
  • Full extraction + resolution + graph suites → 536 passing, no regressions. Build clean.

Out of scope

Copy-init Calculator c = Calculator(0) records a calls edge to the constructor method rather than instantiates to 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

…#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++ stack-allocation syntax not recorded as 'instantiates' edge

1 participant