mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 294730: Default template arguments for function templates.
This commit is contained in:
parent
84a04a9f2a
commit
c6176c6b67
3 changed files with 27 additions and 1 deletions
|
@ -497,7 +497,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
|
||||
public <T extends IBinding> T assertNonProblem(String section, int len) {
|
||||
if (len <= 0)
|
||||
len= section.length()-len;
|
||||
len= section.length()+len;
|
||||
IBinding binding= binding(section, len);
|
||||
if (binding instanceof IProblemBinding) {
|
||||
IProblemBinding problem= (IProblemBinding) binding;
|
||||
|
|
|
@ -4754,4 +4754,27 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
final String code= getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||
}
|
||||
|
||||
// template <class T, class U = double> void f(T t = 0, U u = 0);
|
||||
// void g() {
|
||||
// f(1, 'c'); // f<int,char>(1,'c')
|
||||
// f(1); // f<int,double>(1,0)
|
||||
// f(); // error: T cannot be deduced
|
||||
// f<int>(); // f<int,double>(0,0)
|
||||
// f<int,char>(); // f<int,char>(0,0)
|
||||
// }
|
||||
public void testDefaultTemplateArgsForFunctionTemplates_294730() throws Exception {
|
||||
final String code= getAboveComment();
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
|
||||
ICPPTemplateInstance f= bh.assertNonProblem("f(1, 'c');", 1);
|
||||
assertEquals("<int,char>", ASTTypeUtil.getArgumentListString(f.getTemplateArguments(), true));
|
||||
f= bh.assertNonProblem("f(1);", 1);
|
||||
assertEquals("<int,double>", ASTTypeUtil.getArgumentListString(f.getTemplateArguments(), true));
|
||||
bh.assertProblem("f();", 1);
|
||||
f= bh.assertNonProblem("f<int>();", -3);
|
||||
assertEquals("<int,double>", ASTTypeUtil.getArgumentListString(f.getTemplateArguments(), true));
|
||||
f= bh.assertNonProblem("f<int,char>();", -3);
|
||||
assertEquals("<int,char>", ASTTypeUtil.getArgumentListString(f.getTemplateArguments(), true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -364,6 +364,9 @@ public class TemplateArgumentDeduction {
|
|||
deducedArg= tpar.getDefaultValue();
|
||||
if (deducedArg != null) {
|
||||
deducedArg= CPPTemplates.instantiateArgument(deducedArg, tpMap, -1, null);
|
||||
if (deducedArg != null) {
|
||||
tpMap.put(tpar, deducedArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deducedArg == null)
|
||||
|
|
Loading…
Add table
Reference in a new issue