1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Recursive user-define operator->, bug 205964.

This commit is contained in:
Markus Schorn 2008-05-28 14:38:50 +00:00
parent 0417976c9e
commit 680007453f
2 changed files with 35 additions and 4 deletions

View file

@ -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());
}
} }

View file

@ -954,11 +954,17 @@ public class CPPVisitor {
IType type = getExpressionType(owner); IType type = getExpressionType(owner);
if (fieldReference.isPointerDereference()) { if (fieldReference.isPointerDereference()) {
type= getUltimateTypeUptoPointers(type); type= getUltimateTypeUptoPointers(type);
// 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) { if (type instanceof ICPPClassType) {
ICPPFunction op = CPPSemantics.findOperator(fieldReference, (ICPPClassType) type); ICPPFunction op = CPPSemantics.findOperator(fieldReference, (ICPPClassType) type);
if (op != null) { if (op != null) {
type = op.getType().getReturnType(); type = op.getType().getReturnType();
} }
} else {
break;
}
} }
} }
type = getUltimateType(type, false); type = getUltimateType(type, false);