Skip to content

fix(cpp): emit instantiates edge for stack-allocation constructor syntax#1036

Open
Dshuishui wants to merge 1 commit into
colbymchenry:mainfrom
Dshuishui:fix/cpp-stack-allocation-instantiates
Open

fix(cpp): emit instantiates edge for stack-allocation constructor syntax#1036
Dshuishui wants to merge 1 commit into
colbymchenry:mainfrom
Dshuishui:fix/cpp-stack-allocation-instantiates

Conversation

@Dshuishui

Copy link
Copy Markdown

Summary

C++ stack-allocation syntax (ClassName var(args)) does not produce an
instantiates edge. Heap allocation (new ClassName(args)) works correctly
because new_expression is in INSTANTIATION_KINDS, but the stack form is
parsed by tree-sitter as a declaration node, which is never matched.

This fix adds a branch inside visitFunctionBody's body walker that detects
the pattern: a declaration node whose type field resolves to a class name
(via the existing normalizeCppReturnType primitive filter) and whose
init_declarator child contains an argument_list. When matched, an
instantiates unresolved reference is pushed — the same shape that
extractInstantiation produces for new_expression.

What's covered

  • Calculator calc(0)caller --[instantiates]--> Calculator
  • int x(5) → skipped (int is in CPP_NON_CLASS_RETURN) ✓
  • Calculator calc = other → skipped (no argument_list in declarator) ✓

Known limitations

  • Default constructor (Calculator calc;) — no init_declarator child,
    so no edge is emitted. Can be addressed in a follow-up.
  • Brace initialization (Calculator calc{0}) — uses initializer_list
    rather than argument_list, not covered here.

Closes #1035

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4de2d123cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +4253 to +4255
const typeName = typeNode
? normalizeCppReturnType(getNodeText(typeNode, this.source))
: undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve pointer qualifiers before emitting instantiations

Computing the target from only the declaration type field, and with a return-type normalizer that strips pointers/references and unwraps smart pointers, makes direct-initialized holders look like object construction. In C++ declarations such as Foo *p(nullptr), Foo &r(existing), or std::unique_ptr<Foo> p(nullptr), the later argument_list check still passes and this records instantiates Foo even though no Foo object is constructed at that declaration, polluting "what instantiates Foo" results in common pointer/RAII code. Please inspect the declarator shape and avoid unwrapping holder types for this extraction path.

Useful? React with 👍 / 👎.

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