1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36:01 +02:00

Function template with member pointer, bug 266532.

This commit is contained in:
Markus Schorn 2009-03-03 08:21:06 +00:00
parent 5bf8936d3c
commit 6c715831a4
2 changed files with 16 additions and 29 deletions

View file

@ -2232,7 +2232,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// void test() { // void test() {
// f(&A::m); // f(&A::m);
// } // }
public void _testFunctionTemplate_266532() throws Exception { public void testFunctionTemplate_266532() throws Exception {
BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
bh.assertNonProblem("f(&A::m);", 1, ICPPFunction.class); bh.assertNonProblem("f(&A::m);", 1, ICPPFunction.class);
} }

View file

@ -1377,9 +1377,14 @@ public class CPPTemplates {
for (int j= 0; j < len; j++) { for (int j= 0; j < len; j++) {
IType par= instPars[j]; IType par= instPars[j];
if (isDependentType(par)) { if (isDependentType(par)) {
// 14.8.2.1 par= SemanticUtil.getNestedType(par, SemanticUtil.TDEF); // adjustParameterType preserves typedefs
par= SemanticUtil.adjustParameterType(par, true); par= SemanticUtil.adjustParameterType(par, false);
if (!deduceTemplateParameterMap(par, fnArgs[j], map)) { // 14.8.2.1.2
final boolean isReferenceType = par instanceof ICPPReferenceType;
final IType arg= getArgumentTypeForDeduction(fnArgs[j], isReferenceType);
par= getParameterTypeForDeduction(par, isReferenceType);
if (!deduceTemplateParameterMap(par, arg, map)) {
return false; return false;
} }
} }
@ -1437,23 +1442,12 @@ public class CPPTemplates {
/** /**
* 14.8.2.1-2 If P is a cv-qualified type, the top level cv-qualifiers of P's type are ignored for type * 14.8.2.1-2 If P is a cv-qualified type, the top level cv-qualifiers of P's type are ignored for type
* deduction. If P is a reference type, the type referred to by P is used for Type deduction. * deduction. If P is a reference type, the type referred to by P is used for Type deduction.
* @param pSymbol
* @return
*/ */
static private IType getParameterTypeForDeduction(IType pType) { static private IType getParameterTypeForDeduction(IType pType, boolean isReferenceType) {
IType result = pType; if (isReferenceType) {
try { return SemanticUtil.getNestedType(pType, SemanticUtil.REF | SemanticUtil.TDEF);
if (pType instanceof IQualifierType) {
result = ((IQualifierType) pType).getType();
} else if (pType instanceof ICPPReferenceType) {
result = ((ICPPReferenceType) pType).getType();
} else if (pType instanceof CPPPointerType) {
result = ((CPPPointerType) pType).stripQualifiers();
}
} catch (DOMException e) {
result = e.getProblem();
} }
return result; return SemanticUtil.getNestedType(pType, SemanticUtil.TDEF | SemanticUtil.CVQ | SemanticUtil.PTR_CVQ);
} }
/** /**
@ -1481,24 +1475,17 @@ public class CPPTemplates {
result = new CPPPointerType(((IArrayType) type).getType()); result = new CPPPointerType(((IArrayType) type).getType());
} else if (type instanceof IFunctionType) { } else if (type instanceof IFunctionType) {
result = new CPPPointerType(type); result = new CPPPointerType(type);
} else if (type instanceof IQualifierType) { } else {
result = ((IQualifierType) type).getType(); result = SemanticUtil.getNestedType(type, SemanticUtil.TDEF | SemanticUtil.CVQ | SemanticUtil.PTR_CVQ );
} else if (type instanceof CPPPointerType) { }
result = ((CPPPointerType) type).stripQualifiers();
}
} catch (DOMException e) { } catch (DOMException e) {
result = e.getProblem(); result = e.getProblem();
} }
} }
return result; return result;
} }
private static boolean deduceTemplateParameterMap(IType p, IType a, CPPTemplateParameterMap map) throws DOMException { private static boolean deduceTemplateParameterMap(IType p, IType a, CPPTemplateParameterMap map) throws DOMException {
boolean pIsAReferenceType = (p instanceof ICPPReferenceType);
p = getParameterTypeForDeduction(p);
a = getArgumentTypeForDeduction(a, pIsAReferenceType);
while (p != null) { while (p != null) {
while (a instanceof ITypedef) while (a instanceof ITypedef)
a = ((ITypedef) a).getType(); a = ((ITypedef) a).getType();