From fe433d6e340d2aca057c1829979e336eedef1fb6 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Mon, 22 Jul 2013 21:35:37 -0400 Subject: [PATCH] Bug 413204 - "field could not be resolved" error in function returning function pointer Change-Id: I9f2e9b0f46a46232961948fd3d4310e520d95774 Signed-off-by: Nathan Ridge Reviewed-on: https://git.eclipse.org/r/14763 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../core/parser/tests/ast2/AST2KnRTests.java | 35 +++++++++---------- .../cdt/core/parser/tests/ast2/AST2Tests.java | 9 +++++ .../internal/core/dom/parser/c/CVisitor.java | 6 +++- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java index dc852761b13..f642ae16b1b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java @@ -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); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 72e767e0207..b88622d8481 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -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); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index ec22a238aee..f0a49f4fce3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -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);