summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-07-22 21:35:37 (EDT)
committerSergey Prigogin2013-07-23 19:16:58 (EDT)
commitfe433d6e340d2aca057c1829979e336eedef1fb6 (patch)
tree10bda469281508ef79017289cdf7ecdd4410cbdb
parenta390496044e82b21b2d0ad727784e2138c645c7c (diff)
downloadorg.eclipse.cdt-fe433d6e340d2aca057c1829979e336eedef1fb6.zip
org.eclipse.cdt-fe433d6e340d2aca057c1829979e336eedef1fb6.tar.gz
org.eclipse.cdt-fe433d6e340d2aca057c1829979e336eedef1fb6.tar.bz2
Bug 413204 - "field could not be resolved" error in function returningrefs/changes/63/14763/2
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>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java35
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java6
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 dc85276..f642ae1 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 72e767e..b88622d 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 ec22a23..f0a49f4 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);