1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

Bug 367562: Type deduction for cv-qualified function and pointer types.

This commit is contained in:
Markus Schorn 2012-01-02 16:39:48 +01:00
parent ae559e16d8
commit 73d717b386
2 changed files with 34 additions and 13 deletions

View file

@ -5677,4 +5677,16 @@ public class AST2TemplateTests extends AST2BaseTest {
public void testPackExpansionsAsArguments_367560() throws Exception { public void testPackExpansionsAsArguments_367560() throws Exception {
parseAndCheckBindings(); parseAndCheckBindings();
} }
// template <typename> class A;
// template <typename T> class A<void (T::*)()> {};
// template <typename T> class A<void (T::*)() const> {};
//
// struct S {};
// int main() {
// A<void (S::*)()> m;
// }
public void testDeductionForConstFunctionType_367562() throws Exception {
parseAndCheckBindings();
}
} }

View file

@ -293,7 +293,7 @@ public class TemplateArgumentDeduction {
p= getArgumentTypeForDeduction(p, a instanceof ICPPReferenceType); p= getArgumentTypeForDeduction(p, a instanceof ICPPReferenceType);
a= SemanticUtil.getNestedType(a, SemanticUtil.REF | SemanticUtil.TDEF); a= SemanticUtil.getNestedType(a, SemanticUtil.REF | SemanticUtil.TDEF);
TemplateArgumentDeduction deduct= new TemplateArgumentDeduction(tmplParams, null, map, 0); TemplateArgumentDeduction deduct= new TemplateArgumentDeduction(tmplParams, null, map, 0);
if (!deduct.fromType(p, a, false)) { if (!deduct.fromType(p, a, true)) {
return null; return null;
} }
@ -664,18 +664,24 @@ public class TemplateArgumentDeduction {
} else if (p instanceof ICPPPointerToMemberType) { } else if (p instanceof ICPPPointerToMemberType) {
if (!(a instanceof ICPPPointerToMemberType)) if (!(a instanceof ICPPPointerToMemberType))
return false; return false;
if (!fromType(((ICPPPointerToMemberType) p).getMemberOfClass(), final ICPPPointerToMemberType ptrP = (ICPPPointerToMemberType) p;
((ICPPPointerToMemberType) a).getMemberOfClass(), false)) { final ICPPPointerToMemberType ptrA = (ICPPPointerToMemberType) a;
if (!allowCVQConversion && (ptrP.isConst() != ptrA.isConst() || ptrP.isVolatile() != ptrA.isVolatile()))
return false;
if (!fromType(ptrP.getMemberOfClass(), ptrA.getMemberOfClass(), false)) {
return false; return false;
} }
p = ((ICPPPointerToMemberType) p).getType(); p = ptrP.getType();
a = ((ICPPPointerToMemberType) a).getType(); a = ptrA.getType();
} else if (p instanceof IPointerType) { } else if (p instanceof IPointerType) {
if (!(a instanceof IPointerType)) { if (!(a instanceof IPointerType))
return false; return false;
} final IPointerType ptrP = (IPointerType) p;
p = ((IPointerType) p).getType(); final IPointerType ptrA = (IPointerType) a;
a = ((IPointerType) a).getType(); if (!allowCVQConversion && (ptrP.isConst() != ptrA.isConst() || ptrP.isVolatile() != ptrA.isVolatile()))
return false;
p = ptrP.getType();
a = ptrA.getType();
} else if (p instanceof ICPPReferenceType) { } else if (p instanceof ICPPReferenceType) {
if (!(a instanceof ICPPReferenceType)) { if (!(a instanceof ICPPReferenceType)) {
return false; return false;
@ -730,10 +736,10 @@ public class TemplateArgumentDeduction {
if (remaining != CVQualifier.NONE) { if (remaining != CVQualifier.NONE) {
a= SemanticUtil.addQualifiers(a, remaining.isConst(), remaining.isVolatile(), remaining.isRestrict()); a= SemanticUtil.addQualifiers(a, remaining.isConst(), remaining.isVolatile(), remaining.isRestrict());
} }
} else if (p instanceof IFunctionType) { } else if (p instanceof ICPPFunctionType) {
if (!(a instanceof IFunctionType)) if (!(a instanceof ICPPFunctionType))
return false; return false;
return fromFunctionType((IFunctionType) p, (IFunctionType) a); return fromFunctionType((ICPPFunctionType) p, (ICPPFunctionType) a);
} else if (p instanceof ICPPTemplateParameter) { } else if (p instanceof ICPPTemplateParameter) {
ICPPTemplateArgument current= fDeducedArgs.getArgument(((ICPPTemplateParameter) p).getParameterID(), fPackOffset); ICPPTemplateArgument current= fDeducedArgs.getArgument(((ICPPTemplateParameter) p).getParameterID(), fPackOffset);
if (current != null) { if (current != null) {
@ -820,7 +826,10 @@ public class TemplateArgumentDeduction {
return true; return true;
} }
private boolean fromFunctionType(IFunctionType ftp, IFunctionType fta) throws DOMException { private boolean fromFunctionType(ICPPFunctionType ftp, ICPPFunctionType fta) throws DOMException {
if (ftp.isConst() != fta.isConst() || ftp.isVolatile() != fta.isVolatile())
return false;
if (!fromType(ftp.getReturnType(), fta.getReturnType(), false)) if (!fromType(ftp.getReturnType(), fta.getReturnType(), false))
return false; return false;