Fix CxxAstUtils.getReturnType for functions returning function pointers#2
Open
Copilot wants to merge 2 commits into
Open
Fix CxxAstUtils.getReturnType for functions returning function pointers#2Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
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>
Copilot created this pull request from a session on behalf of
strimo378
May 6, 2026 04:38
View session
…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>
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.
CxxAstUtils.getReturnType()incorrectly handles functions returning function pointersCxxAstUtils.getReturnType()to use the public API when the function declarator is nested inside another declaratorCxxAstUtilsTest(both C and C++) that reproduce the bug and verify the fixCPPVisitor.createTypecall to a single line (as required by the Eclipse formatter)