From 680007453fac2a314629ab35c088c70078537b63 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 28 May 2008 14:38:50 +0000 Subject: [PATCH] Recursive user-define operator->, bug 205964. --- .../core/parser/tests/ast2/AST2CPPTests.java | 25 +++++++++++++++++++ .../dom/parser/cpp/semantics/CPPVisitor.java | 14 ++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index d005ecb1ef8..990ebed377e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -5604,4 +5604,29 @@ public class AST2CPPTests extends AST2BaseTest { } } } + + // class A { + // public: + // void doA() {} + // }; + // + // class FirstLevelProxy { + // public: + // A* operator->() {A *a = new A(); return a;} // leaky + // void doFLP() {} + // }; + // + // class SecondLevelProxy { + // public: + // FirstLevelProxy operator->() {FirstLevelProxy p; return p;} + // void doSLP() {} + // }; + // + // int main(int argc, char **argv) { + // SecondLevelProxy p2; + // p2->doA(); + // } + public void testRecursiveUserDefinedFieldAccess_Bug205964() throws Exception { + parseAndCheckBindings(getAboveComment()); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index cff32af0452..f483a0c25c8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -954,10 +954,16 @@ public class CPPVisitor { IType type = getExpressionType(owner); if (fieldReference.isPointerDereference()) { type= getUltimateTypeUptoPointers(type); - if (type instanceof ICPPClassType) { - ICPPFunction op = CPPSemantics.findOperator(fieldReference, (ICPPClassType) type); - if (op != null) { - type = op.getType().getReturnType(); + // bug 205964: as long as the type is a class type, recurse. + // Be defensive and allow a max of 10 levels. + for (int j = 0; j < 10; j++) { + if (type instanceof ICPPClassType) { + ICPPFunction op = CPPSemantics.findOperator(fieldReference, (ICPPClassType) type); + if (op != null) { + type = op.getType().getReturnType(); + } + } else { + break; } } }