mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-16 13:35:22 +02:00
Bug 416280 - Name resolution problem with alias template. Fix for the
test case in comment #6.
This commit is contained in:
parent
22078c723d
commit
7372e983a1
2 changed files with 43 additions and 8 deletions
|
@ -7094,7 +7094,23 @@ public class AST2TemplateTests extends AST2TestBase {
|
||||||
// void test(A<int>* c) {
|
// void test(A<int>* c) {
|
||||||
// f(c);
|
// f(c);
|
||||||
// }
|
// }
|
||||||
public void testAliasTemplate_416280() throws Exception {
|
public void testAliasTemplate_416280_1() throws Exception {
|
||||||
|
parseAndCheckBindings();
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// struct C {};
|
||||||
|
//
|
||||||
|
// template<typename U>
|
||||||
|
// struct A {
|
||||||
|
// template<typename V>
|
||||||
|
// using B = C<V>;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// struct D : public A<char> {
|
||||||
|
// B<int> b;
|
||||||
|
// };
|
||||||
|
public void testAliasTemplate_416280_2() throws Exception {
|
||||||
parseAndCheckBindings();
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||||
|
@ -686,19 +687,27 @@ public class CPPTemplates {
|
||||||
IASTName templateName = id.getTemplateName();
|
IASTName templateName = id.getTemplateName();
|
||||||
IBinding template = templateName.resolvePreBinding();
|
IBinding template = templateName.resolvePreBinding();
|
||||||
|
|
||||||
// Alias Template.
|
// Alias template.
|
||||||
if (template instanceof ICPPAliasTemplate) {
|
if (template instanceof ICPPAliasTemplate) {
|
||||||
ICPPAliasTemplate aliasTemplate = (ICPPAliasTemplate) template;
|
ICPPAliasTemplate aliasTemplate = (ICPPAliasTemplate) template;
|
||||||
IType aliasedType = aliasTemplate.getType();
|
|
||||||
ICPPTemplateArgument[] args = createTemplateArgumentArray(id);
|
ICPPTemplateArgument[] args = createTemplateArgumentArray(id);
|
||||||
args = addDefaultArguments(aliasTemplate, args, id);
|
args = addDefaultArguments(aliasTemplate, args, id);
|
||||||
ICPPTemplateParameterMap parameterMap = createParameterMap(aliasTemplate, args);
|
ICPPTemplateParameterMap parameterMap = createParameterMap(aliasTemplate, args);
|
||||||
|
IType aliasedType = aliasTemplate.getType();
|
||||||
IBinding owner = template.getOwner();
|
IBinding owner = template.getOwner();
|
||||||
ICPPClassSpecialization within = getSpecializationContext(owner);
|
return createAliasTemplaceInstance(aliasTemplate, args, parameterMap, aliasedType, owner, id);
|
||||||
IType instantiatedType = instantiateType(aliasedType, parameterMap, -1, within, id);
|
}
|
||||||
StringBuilder buf= new StringBuilder();
|
|
||||||
buf.append(id.getSimpleID()).append(ASTTypeUtil.getArgumentListString(args, false));
|
// Alias template instance.
|
||||||
return new CPPAliasTemplateInstance(buf.toString().toCharArray(), aliasTemplate, instantiatedType);
|
if (template instanceof ICPPAliasTemplateInstance) {
|
||||||
|
ICPPAliasTemplateInstance aliasTemplateInstance = (ICPPAliasTemplateInstance) template;
|
||||||
|
ICPPTemplateArgument[] args = createTemplateArgumentArray(id);
|
||||||
|
ICPPAliasTemplate aliasTemplate = aliasTemplateInstance.getTemplateDefinition();
|
||||||
|
args = addDefaultArguments(aliasTemplate, args, id);
|
||||||
|
ICPPTemplateParameterMap parameterMap = createParameterMap(aliasTemplate, args);
|
||||||
|
IType aliasedType = aliasTemplateInstance.getType();
|
||||||
|
IBinding owner = aliasTemplateInstance.getOwner();
|
||||||
|
return createAliasTemplaceInstance(aliasTemplate, args, parameterMap, aliasedType, owner, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Class template.
|
// Class template.
|
||||||
|
@ -759,6 +768,16 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IBinding createAliasTemplaceInstance(ICPPAliasTemplate aliasTemplate,
|
||||||
|
ICPPTemplateArgument[] args, ICPPTemplateParameterMap parameterMap, IType aliasedType,
|
||||||
|
IBinding owner, ICPPASTTemplateId id) {
|
||||||
|
ICPPClassSpecialization within = getSpecializationContext(owner);
|
||||||
|
IType instantiatedType = instantiateType(aliasedType, parameterMap, -1, within, id);
|
||||||
|
StringBuilder buf= new StringBuilder();
|
||||||
|
buf.append(id.getSimpleID()).append(ASTTypeUtil.getArgumentListString(args, false));
|
||||||
|
return new CPPAliasTemplateInstance(buf.toString().toCharArray(), aliasTemplate, instantiatedType);
|
||||||
|
}
|
||||||
|
|
||||||
static boolean isClassTemplate(ICPPASTTemplateId id) {
|
static boolean isClassTemplate(ICPPASTTemplateId id) {
|
||||||
IASTNode parentOfName = id.getParent();
|
IASTNode parentOfName = id.getParent();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue