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

232809: apply fix, add regression test

This commit is contained in:
Andrew Ferguson 2008-05-19 15:01:59 +00:00
parent 5965feb288
commit 38c5adb832
3 changed files with 57 additions and 7 deletions

View file

@ -2581,6 +2581,30 @@ public class AST2TemplateTests extends AST2BaseTest {
assertInstance(col.getName(23).resolveBinding(), ICPPTemplateTypeParameter.class);
}
// template <class T>
// struct A {};
//
// template <class T>
// inline const void foo(void (*f)(A<T>), T t) {
// }
//
// const int i= 5;
// template <class T>
// inline const void foo(void (*f)(A<i>), 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<T>
assertInstance(col.getName(7).getParent(), ICPPASTNamedTypeSpecifier.class);
assertInstance(col.getName(7).getParent().getParent(), IASTTypeId.class);
// 17 is i in A<i>
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<typename T1>
// class A {
// public:
// template<typename T2 = Z> class B;
// };
//
// template<> template<typename T3> class A<short>::B {
// public:
// T3 foo() { return (T3) 0; }
// };
//
// void ref() {
// A<short>::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);
}
}

View file

@ -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);

View file

@ -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);
}