1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 20:05:35 +02:00

233889: pointer-to-member declarations in parameter contexts are not typed correctly

This commit is contained in:
Andrew Ferguson 2008-06-25 11:04:44 +00:00
parent cba281ab15
commit e50931293e
3 changed files with 40 additions and 3 deletions

View file

@ -5764,4 +5764,35 @@ public class AST2CPPTests extends AST2BaseTest {
IASTProblemDeclaration pdecl= getDeclaration(ls, 1);
assertEquals("+error", pdecl.getRawSignature());
}
// class C;
// void func(void (C::*m)(int) const);
public void test233889_a() throws Exception {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
ICPPFunction func= bh.assertNonProblem("func(", 4, ICPPFunction.class);
assertEquals(1,func.getParameters().length);
IType type= func.getParameters()[0].getType();
ICPPPointerToMemberType ptm= assertInstance(type, ICPPPointerToMemberType.class);
ICPPFunctionType t= ((ICPPFunctionType)ptm.getType());
assertTrue(t.isConst());
}
// struct C {
// int m1(int a);
// int m2(int a) const;
// };
//
// C* func(int (C::*m)(int) const);
// C* func(int (C::*m)(int));
//
// void ref() {
// func(&C::m1);
// func(&C::m2);
// }
public void testBug233889_b() throws Exception {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
ICPPFunction fn1= bh.assertNonProblem("func(&C::m1", 4, ICPPFunction.class);
ICPPFunction fn2= bh.assertNonProblem("func(&C::m2", 4, ICPPFunction.class);
assertNotSame(fn1, fn2);
}
}

View file

@ -2055,7 +2055,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// func(c, &C::m1);
// func(d, &C::m2);
// }
public void _testBug233889() throws Exception {
public void testBug233889() throws Exception {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
ICPPFunction fn1= bh.assertNonProblem("func(c", 4, ICPPFunction.class);
ICPPFunction fn2= bh.assertNonProblem("func(d", 4, ICPPFunction.class);

View file

@ -1564,6 +1564,13 @@ public class CPPVisitor {
IScope scope = fnDtor.getFunctionScope();
IType thisType= getThisType(scope);
IASTDeclarator nested = fnDtor.getNestedDeclarator();
if(thisType == null && nested != null) {
IType pts= getPointerTypes(new CPPBasicType(-1,-1), nested);
if(pts instanceof ICPPPointerToMemberType) {
thisType= new CPPPointerType(((ICPPPointerToMemberType)pts).getMemberOfClass());
}
}
if (thisType instanceof IPointerType) {
try {
IType classType = ((IPointerType) thisType).getType();
@ -1574,7 +1581,6 @@ public class CPPVisitor {
thisType = null;
}
IType type = new CPPFunctionType(returnType, pTypes, (IPointerType) thisType);
IASTDeclarator nested = fnDtor.getNestedDeclarator();
if (nested != null) {
return createType(type, nested);
}