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:
parent
5965feb288
commit
38c5adb832
3 changed files with 57 additions and 7 deletions
|
@ -2581,6 +2581,30 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
assertInstance(col.getName(23).resolveBinding(), ICPPTemplateTypeParameter.class);
|
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.
|
// // From discussion in 207840. See 14.3.4.
|
||||||
// class A {};
|
// class A {};
|
||||||
//
|
//
|
||||||
|
@ -2622,4 +2646,26 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
assertSame(f1, f2);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IField;
|
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.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
|
@ -86,7 +87,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements
|
||||||
if (base instanceof IType) {
|
if (base instanceof IType) {
|
||||||
IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap, getScope());
|
IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap, getScope());
|
||||||
specBase = SemanticUtil.getUltimateType(specBase, false);
|
specBase = SemanticUtil.getUltimateType(specBase, false);
|
||||||
if (specBase instanceof IBinding) {
|
if (specBase instanceof IBinding && !(specBase instanceof IProblemBinding)) {
|
||||||
((ICPPInternalBase)specBinding).setBaseClass((IBinding)specBase);
|
((ICPPInternalBase)specBinding).setBaseClass((IBinding)specBase);
|
||||||
}
|
}
|
||||||
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBinding);
|
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBinding);
|
||||||
|
|
|
@ -804,13 +804,16 @@ public class CPPSemantics {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = bases.length;
|
for(ICPPBase base : bases) {
|
||||||
for (int i = 0; i < size; i++) {
|
if(base instanceof IProblemBinding)
|
||||||
inherited = null;
|
continue;
|
||||||
IBinding b = bases[i].getBaseClass();
|
|
||||||
|
IBinding b = base.getBaseClass();
|
||||||
if (b instanceof ICPPClassType == false)
|
if (b instanceof ICPPClassType == false)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
inherited = null;
|
||||||
|
|
||||||
final ICPPClassType cls= (ICPPClassType) b;
|
final ICPPClassType cls= (ICPPClassType) b;
|
||||||
final ICPPScope parent = (ICPPScope) cls.getCompositeScope();
|
final ICPPScope parent = (ICPPScope) cls.getCompositeScope();
|
||||||
|
|
||||||
|
@ -827,8 +830,8 @@ public class CPPSemantics {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bases[i].isVirtual() || !data.visited.containsKey(parent)) {
|
if (!base.isVirtual() || !data.visited.containsKey(parent)) {
|
||||||
if (bases[i].isVirtual()) {
|
if (base.isVirtual()) {
|
||||||
data.visited.put(parent);
|
data.visited.put(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue