diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index 8725f485c90..5bffdd16b37 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.parser.tests.ast2; import junit.framework.TestSuite; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -34,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; 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.ICPPTemplateInstance; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; @@ -5597,50 +5599,6 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { parse(getAboveComment(), ParserLanguage.CPP, false, 0); } - // template int f(T[5]); - // int I = f(0); - // int j = f(0); // invalid array - public void test14_8_2s2a() throws Exception { - parse(getAboveComment(), ParserLanguage.CPP, false, 0); - } - - // template int f(typename T::B*); - // int i = f(0); - public void test14_8_2s2b() throws Exception { - final String content= getAboveComment(); - IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 2); - BindingAssertionHelper bh= new BindingAssertionHelper(content, true); - bh.assertProblem("f<", 1); - bh.assertProblem("f", 6); - } - - // template int f(typename T::B*); - // struct A {}; - // struct C { int B; }; - // int i = f(0); - // int j = f(0); - public void test14_8_2s2c() throws Exception { - final String content= getAboveComment(); - IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 4); - BindingAssertionHelper bh= new BindingAssertionHelper(content, true); - bh.assertProblem("f", 4); - bh.assertProblem("f", 4); - } - - // template int f(int T::*); - // int i = f(0); - public void test14_8_2s2d() throws Exception { - parse(getAboveComment(), ParserLanguage.CPP, true, 2); - } - - // template int f(int); - // int i2 = f(0); // can't conv 1 to int* - public void test14_8_2s2e() throws Exception { - parse(getAboveComment(), ParserLanguage.CPP, false, 1); - } - // template void f(T t); // template void g(const X x); // template void h(Z, Z*); @@ -5661,14 +5619,283 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { parse(getAboveComment(), ParserLanguage.CPP, true, 0); } + // template + // void f(T t = 0, U u = 0); + // void g() { + // f(1, 'c'); // f(1,'c') + // f(1); // f(1,0) + // f(); // error: T cannot be deduced + // f(); // f(0,0) + // f(); // f(0,0) + // } + public void test14_8_2s5() throws Exception { + final String content= getAboveComment(); + BindingAssertionHelper bh= new BindingAssertionHelper(content, true); + ICPPTemplateInstance inst; + inst= bh.assertNonProblem("f(1, 'c')", 1); + assertEquals("", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true)); + inst= bh.assertNonProblem("f(1)", 1); + assertEquals("", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true)); + bh.assertProblem("f()", 1); + inst= bh.assertNonProblem("f()", -2); + assertEquals("", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true)); + inst= bh.assertNonProblem("f()", -2); + assertEquals("", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true)); + } + + // struct X { }; + // struct Y { + // Y(X){} + // }; + // template auto f(T t1, T t2) -> decltype(t1 + t2); // #1 + // X f(Y, Y); // #2 + // X x1, x2; + // X x3 = f(x1, x2); // deduction fails on #1 (cannot add X+X), calls #2 + public void test14_8_2s8a() throws Exception { + parse(getAboveComment(), ParserLanguage.CPP, false, 0); + } + + // template int f(T[5]); + // int I = f(0); + // int j = f(0); // invalid array + public void _test14_8_2s8b() throws Exception { + final String content= getAboveComment(); + BindingAssertionHelper bh= new BindingAssertionHelper(content, true); + bh.assertNonProblem("f(0)", -3); + bh.assertProblem("f(0)", -3); + } + + // template int f(typename T::B*); + // int i = f(0); + public void test14_8_2s8c() throws Exception { + final String content= getAboveComment(); + IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 2); + BindingAssertionHelper bh= new BindingAssertionHelper(content, true); + bh.assertProblem("f<", 1); + bh.assertProblem("f", 6); + } + + // template struct X { }; + // template