1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 413204 - "field could not be resolved" error in function returning

function pointer

Change-Id: I9f2e9b0f46a46232961948fd3d4310e520d95774
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
Reviewed-on: https://git.eclipse.org/r/14763
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Nathan Ridge 2013-07-22 21:35:37 -04:00 committed by Sergey Prigogin
parent a390496044
commit fe433d6e34
3 changed files with 31 additions and 19 deletions

View file

@ -637,25 +637,24 @@ public class AST2KnRTests extends AST2TestBase {
assertTrue(stmts[3] instanceof IASTNullStatement);
}
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=203050
// typedef long time_t;
//
// void (foo)(timep)
// const time_t * const timep;
// {
// struct tm tmp;
//
// bar(timep, &tmp);
// }
//
// int (bar)(timep, tmp)
// const time_t * const timep;
// struct tm * tmp;
// {
// return 0;
// }
public void testBug203050() throws Exception {
StringBuilder buffer = new StringBuilder();
buffer.append("typedef long time_t;\n" + //$NON-NLS-1$
"\n" + //$NON-NLS-1$
"void (foo) (timep)\n" + //$NON-NLS-1$
" const time_t * const timep;\n" + //$NON-NLS-1$
"{\n" + //$NON-NLS-1$
" struct tm tmp;\n" + //$NON-NLS-1$
" bar(timep, &tmp);\n" + //$NON-NLS-1$
"}\n" + //$NON-NLS-1$
"int (bar) (timep, tmp)\n" + //$NON-NLS-1$
" const time_t * const timep;\n" + //$NON-NLS-1$
" struct tm * tmp;\n" + //$NON-NLS-1$
"{\n" + //$NON-NLS-1$
" return 0;\n" + //$NON-NLS-1$
"}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, true);
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true, true);
assertTrue(tu.getDeclarations()[0] instanceof IASTSimpleDeclaration);
assertTrue(tu.getDeclarations()[1] instanceof IASTFunctionDefinition);
assertTrue(tu.getDeclarations()[2] instanceof IASTFunctionDefinition);

View file

@ -7452,4 +7452,13 @@ public class AST2Tests extends AST2TestBase {
}
return count;
}
// typedef struct { int x; } A;
//
// void (*function(A *a))(void) {
// a->x;
// }
public void testFunctionReturningFunctionPointer_413204() throws Exception {
parseAndCheckBindings(getAboveComment(), CPP);
}
}

View file

@ -728,7 +728,11 @@ public class CVisitor extends ASTQueries {
if (parent instanceof IASTParameterDeclaration || parent.getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER) {
IASTDeclarator fdtor = (IASTDeclarator) parent.getParent();
if (ASTQueries.findTypeRelevantDeclarator(fdtor) instanceof IASTFunctionDeclarator) {
IASTName n= ASTQueries.findInnermostDeclarator(fdtor).getName();
IASTDeclarator dtor = fdtor;
while (dtor.getNestedDeclarator() != null && !(dtor.getNestedDeclarator() instanceof IASTFunctionDeclarator)) {
dtor = dtor.getNestedDeclarator();
}
IASTName n = dtor.getName();
IBinding temp = n.resolveBinding();
if (temp != null && temp instanceof CFunction) {
binding = ((CFunction) temp).resolveParameter(name);