From 14aa4c430a09b807512d4a901304f831a6158437 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Tue, 3 May 2005 15:56:18 +0000 Subject: [PATCH] speciializing nested templates with partial specializations --- .../tests/ast2/AST2CPPSpecFailingTest.java | 60 +------------------ .../parser/tests/ast2/AST2CPPSpecTest.java | 49 +++++++++++++++ .../dom/parser/cpp/CPPClassInstanceScope.java | 4 ++ 3 files changed, 55 insertions(+), 58 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java index 67728f6bb5f..5e11cd81c12 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java @@ -609,35 +609,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { buffer.append("template void f(X); // #B\n"); //$NON-NLS-1$ parse(buffer.toString(), ParserLanguage.CPP, true, 2); } - - /** - [--Start Example(CPP 14.5.4.3-2): - template struct A { - template struct B {}; // #1 - template struct B {}; // #2 - }; - template<> template struct A::B {}; // #3 - A::B abcip; // uses #2 - A::B absip; // uses #3 - A::B abci; // uses #1 - --End Example] - */ - public void test14_5_4_3s2() { // TODO raised bug 90681 - StringBuffer buffer = new StringBuffer(); - buffer.append("template struct A {\n"); //$NON-NLS-1$ - buffer.append("template struct B {}; // #1\n"); //$NON-NLS-1$ - buffer.append("template struct B {}; // #2\n"); //$NON-NLS-1$ - buffer.append("};\n"); //$NON-NLS-1$ - buffer.append("template<> template struct A::B {}; // #3\n"); //$NON-NLS-1$ - buffer.append("A::B abcip; // uses #2\n"); //$NON-NLS-1$ - buffer.append("A::B absip; // uses #3\n"); //$NON-NLS-1$ - buffer.append("A::B 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): @@ -873,33 +844,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { } } - /** - [--Start Example(CPP 14.7.3-17): - template class A { - template class B { - void mf(); - }; - }; - template<> template<> A::B { }; - template<> template<> void A::B::mf() { }; - --End Example] - */ - public void test14_7_3s17() { // TODO doesn't compile via g++ - StringBuffer buffer = new StringBuffer(); - buffer.append("template class A {\n"); //$NON-NLS-1$ - buffer.append("template 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::B { };\n"); //$NON-NLS-1$ - buffer.append("template<> template<> void A::B::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 int f(typename T::B*); @@ -911,7 +855,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { buffer.append("template int f(typename T::B*);\n"); //$NON-NLS-1$ buffer.append("int i = f(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(0);\n"); //$NON-NLS-1$ buffer.append("int j = f(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) { } 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 6267b114277..fd71d9a9021 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 @@ -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 struct A { + template struct B {}; // #1 + template struct B {}; // #2 + }; + template<> template struct A::B {}; // #3 + A::B abcip; // uses #2 + A::B absip; // uses #3 + A::B abci; // uses #1 + --End Example] + */ + public void test14_5_4_3s2() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("template struct A {\n"); //$NON-NLS-1$ + buffer.append("template struct B {}; // #1\n"); //$NON-NLS-1$ + buffer.append("template struct B {}; // #2\n"); //$NON-NLS-1$ + buffer.append("};\n"); //$NON-NLS-1$ + buffer.append("template<> template struct A::B {}; // #3\n"); //$NON-NLS-1$ + buffer.append("A::B abcip; // uses #2\n"); //$NON-NLS-1$ + buffer.append("A::B absip; // uses #3\n"); //$NON-NLS-1$ + buffer.append("A::B abci; // uses #1\n"); //$NON-NLS-1$ + + parse(buffer.toString(), ParserLanguage.CPP, true, 0); + } + /** [--Start Example(CPP 14.5.4-4): template 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 A { + template class B { + void mf(); + }; + }; + template<> template<> A::B { }; + template<> template<> void A::B::mf() { }; + --End Example] + */ + public void test14_7_3s17() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("template class A {\n"); //$NON-NLS-1$ + buffer.append("template 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::B { };\n"); //$NON-NLS-1$ + buffer.append("template<> template<> void A::B::mf() { };\n"); //$NON-NLS-1$ + + parse(buffer.toString(), ParserLanguage.CPP, true, 0); + } /** [--Start Example(CPP 14.7.3-10): template class X; // X is a class template diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java index 84bc62069d1..70a16b3285a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java @@ -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 )