mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +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:
parent
a390496044
commit
fe433d6e34
3 changed files with 31 additions and 19 deletions
|
@ -637,25 +637,24 @@ public class AST2KnRTests extends AST2TestBase {
|
||||||
assertTrue(stmts[3] instanceof IASTNullStatement);
|
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 {
|
public void testBug203050() throws Exception {
|
||||||
StringBuilder buffer = new StringBuilder();
|
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true, true);
|
||||||
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);
|
|
||||||
assertTrue(tu.getDeclarations()[0] instanceof IASTSimpleDeclaration);
|
assertTrue(tu.getDeclarations()[0] instanceof IASTSimpleDeclaration);
|
||||||
assertTrue(tu.getDeclarations()[1] instanceof IASTFunctionDefinition);
|
assertTrue(tu.getDeclarations()[1] instanceof IASTFunctionDefinition);
|
||||||
assertTrue(tu.getDeclarations()[2] instanceof IASTFunctionDefinition);
|
assertTrue(tu.getDeclarations()[2] instanceof IASTFunctionDefinition);
|
||||||
|
|
|
@ -7452,4 +7452,13 @@ public class AST2Tests extends AST2TestBase {
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typedef struct { int x; } A;
|
||||||
|
//
|
||||||
|
// void (*function(A *a))(void) {
|
||||||
|
// a->x;
|
||||||
|
// }
|
||||||
|
public void testFunctionReturningFunctionPointer_413204() throws Exception {
|
||||||
|
parseAndCheckBindings(getAboveComment(), CPP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -728,7 +728,11 @@ public class CVisitor extends ASTQueries {
|
||||||
if (parent instanceof IASTParameterDeclaration || parent.getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER) {
|
if (parent instanceof IASTParameterDeclaration || parent.getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER) {
|
||||||
IASTDeclarator fdtor = (IASTDeclarator) parent.getParent();
|
IASTDeclarator fdtor = (IASTDeclarator) parent.getParent();
|
||||||
if (ASTQueries.findTypeRelevantDeclarator(fdtor) instanceof IASTFunctionDeclarator) {
|
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();
|
IBinding temp = n.resolveBinding();
|
||||||
if (temp != null && temp instanceof CFunction) {
|
if (temp != null && temp instanceof CFunction) {
|
||||||
binding = ((CFunction) temp).resolveParameter(name);
|
binding = ((CFunction) temp).resolveParameter(name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue