mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Respect conflict in argument deduction, bug 263716.
This commit is contained in:
parent
9a41478465
commit
f94e5b49c8
2 changed files with 34 additions and 6 deletions
|
@ -3716,4 +3716,21 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||
}
|
||||
|
||||
// template <typename T> class CT {
|
||||
// public:
|
||||
// void append(unsigned int __n, T __c) {}
|
||||
// template<class P> void append(P __first, P __last) {}
|
||||
// };
|
||||
// void test() {
|
||||
// CT<char> x;
|
||||
// x.append(3, 'c');
|
||||
// }
|
||||
public void testConflictInTemplateArgumentDeduction() throws Exception {
|
||||
String code= getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
ICPPMethod m= bh.assertNonProblem("append(3", 6);
|
||||
assertFalse(m instanceof ICPPTemplateInstance);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1390,16 +1390,27 @@ public class CPPTemplates {
|
|||
private static boolean deduceTemplateParameterMapFromFunctionParameters(ICPPFunctionTemplate template, IType[] fnArgs, CPPTemplateParameterMap map) throws DOMException{
|
||||
try {
|
||||
IType[] fnPars = template.getType().getParameterTypes();
|
||||
if (fnPars.length == 0)
|
||||
return true;
|
||||
|
||||
int len= Math.min(fnPars.length, fnArgs.length);
|
||||
IType[] instPars= new IType[len];
|
||||
for (int j= 0; j < len; j++) {
|
||||
IType par= fnPars[j];
|
||||
par= instantiateType(par, map, null);
|
||||
if (!isValidType(par))
|
||||
return false;
|
||||
|
||||
par= SemanticUtil.adjustParameterType(par);
|
||||
if (isDependentType(par) && !deduceTemplateParameterMap(par, fnArgs[j], map)) {
|
||||
IType instPar= instantiateType(par, map, null);
|
||||
if (!isValidType(instPar))
|
||||
return false;
|
||||
instPars[j]= instPar;
|
||||
}
|
||||
|
||||
for (int j= 0; j < len; j++) {
|
||||
IType par= instPars[j];
|
||||
if (isDependentType(par)) {
|
||||
// 14.8.2.1
|
||||
par= SemanticUtil.adjustParameterType(par);
|
||||
if (!deduceTemplateParameterMap(par, fnArgs[j], map)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue