diff options
author | Davin McCall | 2019-05-19 10:02:34 +0000 |
---|---|---|
committer | Nathan Ridge | 2019-05-21 16:59:00 +0000 |
commit | 2734b7ae8295dd4dde0d4383b2bcf7dc708a072a (patch) | |
tree | 9ee6032116c6fb1fc165279001fbc02b09878bcc /core/org.eclipse.cdt.core.tests | |
parent | 1cd0e1df35696e143697533ad3b1b35171d0670a (diff) | |
download | org.eclipse.cdt-2734b7ae8295dd4dde0d4383b2bcf7dc708a072a.tar.gz org.eclipse.cdt-2734b7ae8295dd4dde0d4383b2bcf7dc708a072a.tar.xz org.eclipse.cdt-2734b7ae8295dd4dde0d4383b2bcf7dc708a072a.zip |
Bug 545040 - make array size inference work with initializer lists
Resolution for DR1591 clarified that initializer list size could be used
to deduce array size (if it is a template parameter).
Change-Id: Ic3617e31b125083f1205f91383eb27f5e5a29041
Signed-off-by: Davin McCall <davmac@davmac.org>
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
-rw-r--r-- | core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index c53ccaa951c..c42ac4dd8cd 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -425,6 +425,63 @@ public class AST2TemplateTests extends AST2CPPTestBase { assertEquals(f.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP); } + // template < int N > void f(const int (&v)[N]); + // void main() { + // f({1,2,3}); + // } + public void test_dr1591_DeduceArrayFromInitializerList_a() throws Exception { + IASTTranslationUnit tu = parse(getAboveComment(), CPP); + NameCollector col = new NameCollector(); + tu.accept(col); + + ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(1).resolveBinding(); + assertEquals("f", col.getName(5).toString()); + + IBinding fCall = col.getName(5).resolveBinding(); + assertInstance(fCall, IFunction.class); + IFunction f2 = (IFunction) fCall; + assertInstance(f2, ICPPTemplateInstance.class); + assertSame(f, ((ICPPTemplateInstance) f2).getTemplateDefinition()); + } + + // template < typename T, int N > void f(const T (&v)[N]); + // void main() { + // f({1,2,3}); + // } + public void test_dr1591_DeduceArrayFromInitializerList_b() throws Exception { + IASTTranslationUnit tu = parse(getAboveComment(), CPP); + NameCollector col = new NameCollector(); + tu.accept(col); + + ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(2).resolveBinding(); + assertEquals("f", col.getName(7).toString()); + + IBinding fCall = col.getName(7).resolveBinding(); + assertInstance(fCall, IFunction.class); + IFunction f2 = (IFunction) fCall; + assertInstance(f2, ICPPTemplateInstance.class); + assertSame(f, ((ICPPTemplateInstance) f2).getTemplateDefinition()); + } + + // template < typename T, int N > void f(const T (&v)[N]); + // void main() { + // f({1,2.0,3}); + // } + public void test_dr1591_DeduceArrayFromInitializerList_c() throws Exception { + IASTTranslationUnit tu = parse(getAboveComment(), CPP); + NameCollector col = new NameCollector(); + tu.accept(col); + + ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(2).resolveBinding(); + assertEquals("f", col.getName(7).toString()); + + IBinding fCall = col.getName(7).resolveBinding(); + assertInstance(fCall, IProblemBinding.class); + + IProblemBinding fCallPB = (IProblemBinding) fCall; + assertEquals(IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fCallPB.getID()); + } + // template < class T, template < class X > class U, T *pT > class A { // }; public void testTemplateParameters() throws Exception { |