mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Instantiation of default template argument during argument deduction, bug 272848.
This commit is contained in:
parent
63d41f2395
commit
264e4f5164
5 changed files with 28 additions and 11 deletions
|
@ -2265,7 +2265,7 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
// void test(A<int*> p) {
|
// void test(A<int*> p) {
|
||||||
// f(p);
|
// f(p);
|
||||||
// }
|
// }
|
||||||
public void _testFunctionTemplate_272848_2() throws Exception {
|
public void testFunctionTemplate_272848_2() throws Exception {
|
||||||
final String code = getAboveComment();
|
final String code = getAboveComment();
|
||||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||||
|
|
||||||
|
@ -98,6 +99,16 @@ public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDef
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPPTemplateParameterMap getTemplateParameterMap() {
|
public CPPTemplateParameterMap getTemplateParameterMap() {
|
||||||
|
try {
|
||||||
|
ICPPTemplateParameter[] params = fClassTemplate.getTemplateParameters();
|
||||||
|
int size = Math.min(fArguments.length, params.length);
|
||||||
|
CPPTemplateParameterMap map = new CPPTemplateParameterMap(size);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
map.put(params[i], fArguments[i]);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
} catch (DOMException e) {
|
||||||
|
}
|
||||||
return CPPTemplateParameterMap.EMPTY;
|
return CPPTemplateParameterMap.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007, 2008 QNX Software Systems and others.
|
* Copyright (c) 2007, 2009 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -26,8 +26,8 @@ public interface ICPPDeferredClassInstance extends ICPPUnknownClassType, ICPPTem
|
||||||
ICPPClassTemplate getClassTemplate();
|
ICPPClassTemplate getClassTemplate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an empty map, because template parameters cannot be mapped until
|
* Returns the mapping of the template parameters of the primary class template to the
|
||||||
* all of the arguments are resolved.
|
* arguments of this instance.
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
public ICPPTemplateParameterMap getTemplateParameterMap();
|
public ICPPTemplateParameterMap getTemplateParameterMap();
|
||||||
|
|
|
@ -1661,7 +1661,7 @@ public class CPPTemplates {
|
||||||
pArg= tpars[i].getDefaultValue();
|
pArg= tpars[i].getDefaultValue();
|
||||||
if (pArg == null)
|
if (pArg == null)
|
||||||
return false;
|
return false;
|
||||||
pArg= instantiateArgument(pArg, map, null);
|
pArg= instantiateArgument(pArg, pInst.getTemplateParameterMap(), null);
|
||||||
}
|
}
|
||||||
if (!deduceTemplateParameterMap(pArg, aArgs[i], map))
|
if (!deduceTemplateParameterMap(pArg, aArgs[i], map))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||||
|
@ -201,13 +201,19 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPSpecialization implements ICPP
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectMap getArgumentMap() {
|
|
||||||
return ObjectMap.EMPTY_MAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CPPTemplateParameterMap getTemplateParameterMap() {
|
public CPPTemplateParameterMap getTemplateParameterMap() {
|
||||||
|
try {
|
||||||
|
ICPPTemplateParameter[] params = getClassTemplate().getTemplateParameters();
|
||||||
|
ICPPTemplateArgument[] args = getTemplateArguments();
|
||||||
|
int size = Math.min(args.length, params.length);
|
||||||
|
CPPTemplateParameterMap map = new CPPTemplateParameterMap(size);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
map.put(params[i], args[i]);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
} catch (DOMException e) {
|
||||||
|
}
|
||||||
return CPPTemplateParameterMap.EMPTY;
|
return CPPTemplateParameterMap.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue