1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

speciializing nested templates with partial specializations

This commit is contained in:
Andrew Niefer 2005-05-03 15:56:18 +00:00
parent f8927a9f4c
commit 14aa4c430a
3 changed files with 55 additions and 58 deletions

View file

@ -610,35 +610,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, true, 2);
}
/**
[--Start Example(CPP 14.5.4.3-2):
template<class T> struct A {
template<class T2> struct B {}; // #1
template<class T2> struct B<T2*> {}; // #2
};
template<> template<class T2> struct A<short>::B {}; // #3
A<char>::B<int*> abcip; // uses #2
A<short>::B<int*> absip; // uses #3
A<char>::B<int> abci; // uses #1
--End Example]
*/
public void test14_5_4_3s2() { // TODO raised bug 90681
StringBuffer buffer = new StringBuffer();
buffer.append("template<class T> struct A {\n"); //$NON-NLS-1$
buffer.append("template<class T2> struct B {}; // #1\n"); //$NON-NLS-1$
buffer.append("template<class T2> struct B<T2*> {}; // #2\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("template<> template<class T2> struct A<short>::B {}; // #3\n"); //$NON-NLS-1$
buffer.append("A<char>::B<int*> abcip; // uses #2\n"); //$NON-NLS-1$
buffer.append("A<short>::B<int*> absip; // uses #3\n"); //$NON-NLS-1$
buffer.append("A<char>::B<int> abci; // uses #1\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
assertTrue(false);
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 14.5.5.1-5):
template <int I, int J> A<I+J> f(A<I>, A<J>); // #1
@ -873,33 +844,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
}
}
/**
[--Start Example(CPP 14.7.3-17):
template<class T1> class A {
template<class T2> class B {
void mf();
};
};
template<> template<> A<int>::B<double> { };
template<> template<> void A<char>::B<char>::mf() { };
--End Example]
*/
public void test14_7_3s17() { // TODO doesn't compile via g++
StringBuffer buffer = new StringBuffer();
buffer.append("template<class T1> class A {\n"); //$NON-NLS-1$
buffer.append("template<class T2> class B {\n"); //$NON-NLS-1$
buffer.append("void mf();\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("template<> template<> A<int>::B<double> { };\n"); //$NON-NLS-1$
buffer.append("template<> template<> void A<char>::B<char>::mf() { };\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
assertTrue(false);
} catch (Exception e) {
}
}
/**
[--Start Example(CPP 14.8.2-2b):
template <class T> int f(typename T::B*);
@ -911,7 +855,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
buffer.append("template <class T> int f(typename T::B*);\n"); //$NON-NLS-1$
buffer.append("int i = f<int>(0);\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
parse(buffer.toString(), ParserLanguage.CPP, true, 1);
assertTrue(false);
} catch (Exception e) {
}
@ -934,7 +878,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
buffer.append("int i = f<A>(0);\n"); //$NON-NLS-1$
buffer.append("int j = f<C>(0);\n"); //$NON-NLS-1$
try {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
parse(buffer.toString(), ParserLanguage.CPP, true, 2);
assertTrue(false);
} catch (Exception e) {
}

View file

@ -9133,6 +9133,32 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 14.5.4.3-2):
template<class T> struct A {
template<class T2> struct B {}; // #1
template<class T2> struct B<T2*> {}; // #2
};
template<> template<class T2> struct A<short>::B {}; // #3
A<char>::B<int*> abcip; // uses #2
A<short>::B<int*> absip; // uses #3
A<char>::B<int> abci; // uses #1
--End Example]
*/
public void test14_5_4_3s2() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template<class T> struct A {\n"); //$NON-NLS-1$
buffer.append("template<class T2> struct B {}; // #1\n"); //$NON-NLS-1$
buffer.append("template<class T2> struct B<T2*> {}; // #2\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("template<> template<class T2> struct A<short>::B {}; // #3\n"); //$NON-NLS-1$
buffer.append("A<char>::B<int*> abcip; // uses #2\n"); //$NON-NLS-1$
buffer.append("A<short>::B<int*> absip; // uses #3\n"); //$NON-NLS-1$
buffer.append("A<char>::B<int> abci; // uses #1\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 14.5.4-4):
template<class T1, class T2, int I> class A { }; // #1
@ -10324,6 +10350,29 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 14.7.3-17):
template<class T1> class A {
template<class T2> class B {
void mf();
};
};
template<> template<> A<int>::B<double> { };
template<> template<> void A<char>::B<char>::mf() { };
--End Example]
*/
public void test14_7_3s17() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template<class T1> class A {\n"); //$NON-NLS-1$
buffer.append("template<class T2> class B {\n"); //$NON-NLS-1$
buffer.append("void mf();\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("template<> template<> class A<int>::B<double> { };\n"); //$NON-NLS-1$
buffer.append("template<> template<> void A<char>::B<char>::mf() { };\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
}
/**
[--Start Example(CPP 14.7.3-10):
template<class T> class X; // X is a class template

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
@ -82,6 +83,9 @@ public class CPPClassInstanceScope implements ICPPClassScope {
binding = (IBinding) instanceMap.get( n );
} else {
binding = forceResolve ? n.resolveBinding() : n.getBinding();
if (binding instanceof ICPPClassTemplatePartialSpecialization ){
binding = null;
}
if( binding != null ){
binding = CPPTemplates.createSpecialization( this, binding, instance.getArgumentMap() );
if( instanceMap == ObjectMap.EMPTY_MAP )