From 38c5adb83271c78551e59accc146a68283b2a915 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Mon, 19 May 2008 15:01:59 +0000 Subject: [PATCH] 232809: apply fix, add regression test --- .../parser/tests/ast2/AST2TemplateTests.java | 46 +++++++++++++++++++ .../parser/cpp/CPPClassSpecialization.java | 3 +- .../parser/cpp/semantics/CPPSemantics.java | 15 +++--- 3 files changed, 57 insertions(+), 7 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 551e2caa28f..caaf64ab8b2 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 @@ -2581,6 +2581,30 @@ public class AST2TemplateTests extends AST2BaseTest { assertInstance(col.getName(23).resolveBinding(), ICPPTemplateTypeParameter.class); } + // template + // struct A {}; + // + // template + // inline const void foo(void (*f)(A), T t) { + // } + // + // const int i= 5; + // template + // inline const void foo(void (*f)(A), T* t) { // disallowed, but we're testing the AST + // } + public void _testTypeIdAsTemplateArgumentIsTypeId_229942_g() throws Exception { + IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true); + CPPNameCollector col = new CPPNameCollector(); + tu.accept(col); + + // 7 is T in A + assertInstance(col.getName(7).getParent(), ICPPASTNamedTypeSpecifier.class); + assertInstance(col.getName(7).getParent().getParent(), IASTTypeId.class); + + // 17 is i in A + assertInstance(col.getName(17).getParent(), IASTIdExpression.class); + } + // // From discussion in 207840. See 14.3.4. // class A {}; // @@ -2622,4 +2646,26 @@ public class AST2TemplateTests extends AST2BaseTest { assertSame(f1, f2); } + // class Z {}; + // + // template + // class A { + // public: + // template class B; + // }; + // + // template<> template class A::B { + // public: + // T3 foo() { return (T3) 0; } + // }; + // + // void ref() { + // A::B<> b; + // } + public void testNestedTemplateDefinitionParameter() throws Exception { + BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); + ICPPTemplateTypeParameter T3a= ba.assertNonProblem("T3 f", 2, ICPPTemplateTypeParameter.class); + ICPPTemplateTypeParameter T3b= ba.assertNonProblem("T3)", 2, ICPPTemplateTypeParameter.class); + ICPPClassType b= ba.assertNonProblem("B<>", 3, ICPPClassType.class, ICPPTemplateInstance.class); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java index b51df3ff117..572af360ee1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; @@ -86,7 +87,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements if (base instanceof IType) { IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap, getScope()); specBase = SemanticUtil.getUltimateType(specBase, false); - if (specBase instanceof IBinding) { + if (specBase instanceof IBinding && !(specBase instanceof IProblemBinding)) { ((ICPPInternalBase)specBinding).setBaseClass((IBinding)specBase); } result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBinding); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index c0c3f58bd7a..14678b4e2be 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -804,13 +804,16 @@ public class CPPSemantics { return null; } - int size = bases.length; - for (int i = 0; i < size; i++) { - inherited = null; - IBinding b = bases[i].getBaseClass(); + for(ICPPBase base : bases) { + if(base instanceof IProblemBinding) + continue; + + IBinding b = base.getBaseClass(); if (b instanceof ICPPClassType == false) continue; + inherited = null; + final ICPPClassType cls= (ICPPClassType) b; final ICPPScope parent = (ICPPScope) cls.getCompositeScope(); @@ -827,8 +830,8 @@ public class CPPSemantics { continue; } - if (!bases[i].isVirtual() || !data.visited.containsKey(parent)) { - if (bases[i].isVirtual()) { + if (!base.isVirtual() || !data.visited.containsKey(parent)) { + if (base.isVirtual()) { data.visited.put(parent); }