1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

fix template instances

This commit is contained in:
Andrew Niefer 2005-04-26 21:39:26 +00:00
parent f45b9b7692
commit b3f9f20ed8
4 changed files with 75 additions and 58 deletions

View file

@ -732,30 +732,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
}
}
/**
[--Start Example(CPP 14.3-5):
template<class T> struct A {
~A();
};
void f(A<int>* p, A<int>* q) {
p->A<int>::~A(); // OK: destructor call
q->A<int>::~A<int>(); // OK: destructor call
}
--End Example]
*/
public void test14_3s5() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template<class T> struct A {\n"); //$NON-NLS-1$
buffer.append("~A();\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("void f(A<int>* p, A<int>* q) {\n"); //$NON-NLS-1$
buffer.append("p->A<int>::~A(); // OK: destructor call\n"); //$NON-NLS-1$
buffer.append("q->A<int>::~A<int>(); // OK: destructor call\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 5);
}
/**
[--Start Example(CPP 14.3.2-5):
template<const int* pci> struct X { };
@ -1042,39 +1018,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
}
}
/**
[--Start Example(CPP 14.7.1-5):
template <class T> struct S {
operator int();
};
void f(int);
void f(S<int>&);
void f(S<float>);
void g(S<int>& sr) {
f(sr); //instantiation of S<int> allowed but not required
// instantiation of S<float> allowed but not required
};
--End Example]
*/
public void test14_7_1s5() { // TODO already have similar bug
StringBuffer buffer = new StringBuffer();
buffer.append("template <class T> struct S {\n"); //$NON-NLS-1$
buffer.append("operator int();\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("void f(int);\n"); //$NON-NLS-1$
buffer.append("void f(S<int>&);\n"); //$NON-NLS-1$
buffer.append("void f(S<float>);\n"); //$NON-NLS-1$
buffer.append("void g(S<int>& sr) {\n"); //$NON-NLS-1$
buffer.append("f(sr); //instantiation of S<int> allowed but not required\n"); //$NON-NLS-1$
buffer.append("// instantiation of S<float> allowed but not required\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
assertTrue(false);
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 14.7.2-2):
template<class T> class Array { void mf(); };

View file

@ -8598,6 +8598,30 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 14.3-5):
template<class T> struct A {
~A();
};
void f(A<int>* p, A<int>* q) {
p->A<int>::~A(); // OK: destructor call
q->A<int>::~A<int>(); // OK: destructor call
}
--End Example]
*/
public void test14_3s5() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template<class T> struct A {\n"); //$NON-NLS-1$
buffer.append("~A();\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("void f(A<int>* p, A<int>* q) {\n"); //$NON-NLS-1$
buffer.append("p->A<int>::~A(); // OK: destructor call\n"); //$NON-NLS-1$
buffer.append("q->A<int>::~A<int>(); // OK: destructor call\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 14.3.1-2):
template <class T> class X { };
@ -9962,6 +9986,36 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 14.7.1-5):
template <class T> struct S {
operator int();
};
void f(int);
void f(S<int>&);
void f(S<float>);
void g(S<int>& sr) {
f(sr); //instantiation of S<int> allowed but not required
// instantiation of S<float> allowed but not required
};
--End Example]
*/
public void test14_7_1s5() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template <class T> struct S {\n"); //$NON-NLS-1$
buffer.append("operator int();\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("void f(int);\n"); //$NON-NLS-1$
buffer.append("void f(S<int>&);\n"); //$NON-NLS-1$
buffer.append("void f(S<float>);\n"); //$NON-NLS-1$
buffer.append("void g(S<int>& sr) {\n"); //$NON-NLS-1$
buffer.append("f(sr); //instantiation of S<int> allowed but not required\n"); //$NON-NLS-1$
buffer.append("// instantiation of S<float> allowed but not required\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 14.7.1-10):
namespace N {

View file

@ -838,4 +838,24 @@ public class AST2TemplateTests extends AST2BaseTest {
assertTrue( type instanceof IBasicType );
assertEquals( ((IBasicType)type).getType(), IBasicType.t_int );
}
public void testInstances() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template < class T > class A { \n"); //$NON-NLS-1$
buffer.append(" A< int > a; \n"); //$NON-NLS-1$
buffer.append("}; \n"); //$NON-NLS-1$
buffer.append("void f( A<int> p ) { } \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept( col );
ICPPClassTemplate A = (ICPPClassTemplate) col.getName(1).resolveBinding();
ICPPClassType A1 = (ICPPClassType) col.getName(2).resolveBinding();
ICPPClassType A2 = (ICPPClassType) col.getName(6).resolveBinding();
assertSame( A1, A2 );
assertTrue( A1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)A1).getOriginalBinding(), A );
}
}

View file

@ -210,7 +210,7 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
if( args.length == arguments.length ){
int j = 0;
for(; j < args.length; j++) {
if( !( args[j].equals( arguments[j] ) ) )
if( !( args[j].isSameType( arguments[j] ) ) )
break;
}
if( j == args.length ){