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:
parent
0417976c9e
commit
680007453f
2 changed files with 35 additions and 4 deletions
|
@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -954,10 +954,16 @@ public class CPPVisitor {
|
||||||
IType type = getExpressionType(owner);
|
IType type = getExpressionType(owner);
|
||||||
if (fieldReference.isPointerDereference()) {
|
if (fieldReference.isPointerDereference()) {
|
||||||
type= getUltimateTypeUptoPointers(type);
|
type= getUltimateTypeUptoPointers(type);
|
||||||
if (type instanceof ICPPClassType) {
|
// bug 205964: as long as the type is a class type, recurse.
|
||||||
ICPPFunction op = CPPSemantics.findOperator(fieldReference, (ICPPClassType) type);
|
// Be defensive and allow a max of 10 levels.
|
||||||
if (op != null) {
|
for (int j = 0; j < 10; j++) {
|
||||||
type = op.getType().getReturnType();
|
if (type instanceof ICPPClassType) {
|
||||||
|
ICPPFunction op = CPPSemantics.findOperator(fieldReference, (ICPPClassType) type);
|
||||||
|
if (op != null) {
|
||||||
|
type = op.getType().getReturnType();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue