Skip to content

fix(parsers): extract C/C++ functions returning a pointer or reference - #1582

Merged
Shashankss1205 merged 1 commit into
mainfrom
fix/parser-c-cpp-pointer-returns
Aug 5, 2026
Merged

Shashankss1205 merged 1 commit into
mainfrom
fix/parser-c-cpp-pointer-returns

Conversation

@Shashankss1205

Copy link
Copy Markdown
Collaborator

Fixes #1524. Full suite: 1139 passed, 7 skipped, no failures.

The bug

Both queries nested pointer_declarator inside function_declarator. The real AST is the reverse — a pointer return type wraps the function declarator from the outside:

char* f() { }
function_definition > pointer_declarator > function_declarator > identifier

Verified against the grammar:

'char* data() { ... }'      -> pointer_declarator > function_declarator > identifier
'int size() { ... }'        -> function_declarator > identifier
'char** dd() { ... }'       -> pointer_declarator > pointer_declarator > function_declarator > identifier
'int& ref() { ... }'        -> reference_declarator > function_declarator
'char* Buf::at() { ... }'   -> pointer_declarator > function_declarator > qualified_identifier

So c.py's second alternative matched nothing, and cpp.py had no alternative at all.

The half that mattered more

pre_scan_c and pre_scan_cpp carry their own copies of the same inverted shape. That is the cross-file name map, so these functions weren't just missing as nodes — they were missing as call targets, and every call to them stayed unresolved. Both copies are fixed here.

C   pre_scan : ['dup_str', 'grid', 'plain']            # was ['plain']
C++ pre_scan : ['Buf', 'Buf::data', 'Buf::size', 'data',
                'make', 'plain', 'ref', 'size']

Accessors returning T*/T&, factory functions and operator[] are pervasive in C and C++, so this was a large silent gap.

Covered forms

T*, T**, T& (C++ only), and the qualified out-of-line method char* Buf::data() — whose class_context survives the extra wrap, which is asserted separately since that is the case most likely to break.

Tests

tests/unit/parsers/test_c_cpp_pointer_returns.py — 11 tests. Reverting the source changes fails 9 of 11; the 2 that still pass are the plain-int control cases, which is the correct behaviour.

Why no golden moved

Worth stating, since an unchanged golden usually means a change didn't apply. The only pointer-returning function in the C/C++ fixtures is const char* get_color_name in tough_macros.c, and it sits inside an X-macro region tree-sitter cannot parse:

ERROR/missing nodes: [('ERROR', 13), ('ERROR', 66), ('ERROR', 73), ('ERROR', 75), ('ERROR', 79)]

Line 79 is that function. It is unreachable for reasons unrelated to this fix, so the goldens are correctly unchanged. A fixture exercising a plain T* return would be a reasonable follow-up.

🤖 Generated with Claude Code

#1524)

The queries nested `pointer_declarator` inside `function_declarator`. The
real AST is the reverse — a pointer return type wraps the function
declarator from the outside:

    char* f() { }
    function_definition > pointer_declarator > function_declarator > identifier

So the second alternative in c.py matched nothing, and cpp.py had no
alternative at all. No function returning T*, T** or T& was extracted.

`pre_scan_c` and `pre_scan_cpp` carried their own copies of the same
inverted shape, so these functions were also missing from the cross-file
name map — invisible as call targets, not merely absent as nodes. Both
copies are fixed here, which is the half that restores resolution.

Covered forms: T*, T**, T& (C++), and the qualified out-of-line method
`char* Buf::data()`, whose class context survives the extra wrap.

Accessors returning T*/T&, factory functions and operator[] are pervasive
in C and C++, so this was a large silent gap.

No golden moved. The only pointer-returning function in the C/C++ fixtures
is `const char* get_color_name` in tough_macros.c, which sits inside an
X-macro region tree-sitter cannot parse (ERROR node at line 79) — so it is
unreachable for reasons unrelated to this fix.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel

vercel Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
code-graph-context-pack Ready Ready Preview Aug 5, 2026 7:22pm

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Code Graph Analysis

fix(parsers): extract C/C++ functions returning a pointer or reference (#1582)

📊 Interactive Visualization

View the blast radius graph: PR Reviewer Dashboard

📦 Artifacts

The graph JSON has been uploaded as a build artifact: pr-code-graph-1582


Generated by CodeGraphContext using FalkorDB Lite

@Shashankss1205
Shashankss1205 merged commit ca1899d into main Aug 5, 2026
19 checks passed
@Shashankss1205
Shashankss1205 deleted the fix/parser-c-cpp-pointer-returns branch August 5, 2026 19:53
@github-project-automation github-project-automation Bot moved this from Backlog tasks to Done in CGC Progress Board Aug 5, 2026
Shashankss1205 added a commit that referenced this pull request Aug 8, 2026
Ten PRs since 0.5.6 — mostly parser correctness, all with regression tests.

Parsers
- Ruby nested classes no longer delete their parent; method parameters
  extracted at all (#1523, #1527, #1581)
- C/C++ functions returning a pointer or reference are extracted, and
  registered in pre_scan so they resolve as call targets (#1524, #1582)
- C# fields and locals parsed, restoring receiver-type inference for
  `var x = new T(); x.M();` (#1525, #1584)
- JavaScript destructured, array and rest parameters extracted, recording
  the binding names rather than a placeholder (#1527, #1591)

Queries and analysis
- Five defects that returned wrong answers without erroring: inflated
  repository stats, misattributed callers, discarded graph_name,
  count(*) after OPTIONAL MATCH, an ignored tool argument (#1577)
- Dead-code detection made correct and self-consistent, including the
  JS module-level false positive (#600, #1559, #1578)

Indexing
- add_package_to_graph on a flat module no longer indexes the whole
  virtualenv (#1528, #1586)
- SCIP job progress no longer exceeds 100% (#1535, #1583)

Docs and tests
- Database Options table columns realigned (#1590)
- MCP tool definition contract validation (#1580)

Co-authored-by: Claude Fable 5 <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — c5eeaa7d Deployed Aug 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(indexer): C/C++ functions returning a pointer or reference are never extracted — query nests pointer_declarator inside function_declarator instead of outside

1 participant