Skip to content

Fix CxxAstUtils.getReturnType for functions returning function pointers#2

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-function-factory-return-type
Open

Fix CxxAstUtils.getReturnType for functions returning function pointers#2
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-function-factory-return-type

Conversation

Copy link
Copy Markdown

Copilot AI commented May 6, 2026

  • Identify the bug: CxxAstUtils.getReturnType() incorrectly handles functions returning function pointers
  • Fix CxxAstUtils.getReturnType() to use the public API when the function declarator is nested inside another declarator
  • Add tests to CxxAstUtilsTest (both C and C++) that reproduce the bug and verify the fix
  • Fix code cleanliness check: collapse wrapped CPPVisitor.createType call to a single line (as required by the Eclipse formatter)

When a function like `int (*functionFactory(int n))(int, int)` is parsed,
`func.getDeclarator()` returns the inner function declarator nested inside the
outer function declarator. The ONLY_RETURN_TYPE optimization in
CxxAstUtils.getReturnType() does not correctly handle this nested case: it
ends up applying the pointer operator from the inner declarator to the base
type (int) instead of to the outer function type, yielding the wrong return type.

Fix: when the function declarator is nested inside another declarator, fall
back to the public API (binding.getType().getReturnType()) which always
returns the correct type.

Add CxxAstUtilsTest tests for both C and C++ to reproduce and verify the fix.

Agent-Logs-Url: https://github.com/emmtrix/cdt/sessions/1a07c5d3-dd2c-4a27-bb44-160eb258531d

Co-authored-by: strimo378 <59825937+strimo378@users.noreply.github.com>
…single line

Agent-Logs-Url: https://github.com/emmtrix/cdt/sessions/4a36ae34-5126-4f52-8a2a-10ed42f36ee7

Co-authored-by: strimo378 <59825937+strimo378@users.noreply.github.com>
Copilot AI requested a review from strimo378 May 6, 2026 07:58
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.

2 participants