mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Bug 344310: Address of overloaded method for instantiation.
This commit is contained in:
parent
08663d85ab
commit
557c7ee6d6
3 changed files with 54 additions and 10 deletions
|
@ -5385,4 +5385,21 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
public void testTemplateIDAmbiguity_341747d() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// template<typename T> void ft(void (T::* function)()) {}
|
||||
// struct Bar {
|
||||
// template<typename T> Bar(void (T::*function)()) {}
|
||||
// };
|
||||
// struct Foo {
|
||||
// void function() {}
|
||||
// void function(int) {}
|
||||
// };
|
||||
// int test2() {
|
||||
// Bar test(&Foo::function); // Invalid overload of 'Foo::func tion'
|
||||
// ft(&Foo::function);
|
||||
// return 0;
|
||||
// }
|
||||
public void testAddressOfMethodForInstantiation_Bug344310() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2738,16 +2738,38 @@ public class CPPSemantics {
|
|||
}
|
||||
} else if (prop == ICPPASTConstructorInitializer.ARGUMENT) {
|
||||
ICPPASTConstructorInitializer init = (ICPPASTConstructorInitializer) parent;
|
||||
if (init.getArguments().length == 1) {
|
||||
final IASTNode parentOfInit = init.getParent();
|
||||
if (parentOfInit instanceof IASTDeclarator) {
|
||||
IASTDeclarator dtor = (IASTDeclarator) parentOfInit;
|
||||
targetType= CPPVisitor.createType(dtor);
|
||||
} else if (parentOfInit instanceof ICPPASTConstructorChainInitializer) {
|
||||
ICPPASTConstructorChainInitializer memInit= (ICPPASTConstructorChainInitializer) parentOfInit;
|
||||
IBinding var= memInit.getMemberInitializerId().resolveBinding();
|
||||
if (var instanceof IVariable) {
|
||||
targetType= ((IVariable) var).getType();
|
||||
final IASTNode parentOfInit = init.getParent();
|
||||
if (parentOfInit instanceof IASTDeclarator) {
|
||||
IASTDeclarator dtor = (IASTDeclarator) parentOfInit;
|
||||
targetType= CPPVisitor.createType(dtor);
|
||||
} else if (parentOfInit instanceof ICPPASTConstructorChainInitializer) {
|
||||
ICPPASTConstructorChainInitializer memInit= (ICPPASTConstructorChainInitializer) parentOfInit;
|
||||
IBinding var= memInit.getMemberInitializerId().resolveBinding();
|
||||
if (var instanceof IVariable) {
|
||||
targetType= ((IVariable) var).getType();
|
||||
}
|
||||
}
|
||||
targetType= getNestedType(targetType, TDEF | REF | CVTYPE | PTR | MPTR);
|
||||
if (init.getArguments().length != 1 || !(targetType instanceof ICPPFunctionType)) {
|
||||
if (targetType instanceof ICPPClassType) {
|
||||
LookupData data= new LookupData(name);
|
||||
data.setFunctionArguments(false, init.getArguments());
|
||||
try {
|
||||
IBinding ctor = CPPSemantics.resolveFunction(data, ((ICPPClassType) targetType).getConstructors(), true);
|
||||
if (ctor instanceof ICPPConstructor) {
|
||||
int i= 0;
|
||||
for (IASTNode arg : init.getArguments()) {
|
||||
if (arg == node) {
|
||||
IType[] params= ((ICPPConstructor) ctor).getType().getParameterTypes();
|
||||
if (params.length > i) {
|
||||
targetType= params[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||
|
@ -48,6 +49,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerToMemberType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument;
|
||||
|
@ -311,6 +313,9 @@ public class TemplateArgumentDeduction {
|
|||
Set<String> handled= new HashSet<String>();
|
||||
for (ICPPFunction f : fs) {
|
||||
arg= f.getType();
|
||||
if (f instanceof ICPPMethod && !f.isStatic()) {
|
||||
arg= new CPPPointerToMemberType(arg, ((ICPPMethod) f).getClassOwner(), false, false, false);
|
||||
}
|
||||
if (handled.add(ASTTypeUtil.getType(arg, true))) {
|
||||
final CPPTemplateParameterMap state = deduct.saveState();
|
||||
if (deduceFromFunctionArg(par, arg, argCats.get(j), deduct)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue