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

Bug 462764 - Avoid infinite recursion when storing function instance in

index

Change-Id: I922b741e62013941753114ea5c17f401093f18f3
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-12-29 12:06:29 -05:00 committed by Gerrit Code Review @ Eclipse.org
parent b0d66aa777
commit 6b58a751bb
3 changed files with 46 additions and 5 deletions

View file

@ -2870,4 +2870,22 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
// (e.g. because the author omitted a base case) doesn't cause a stack overflow.
checkBindings();
}
// template<int L> constexpr
// auto Bar(char const (&val)[L]) -> int {
// return 0;
// }
//
// template<int K>
// auto Foo() -> int;
//
// template<>
// auto Foo<Bar("")>() -> int {
// return 1;
// }
// // empty file
public void testStackOverflow_462764() throws Exception {
checkBindings();
}
}

View file

@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionInstance;
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.ICPPTemplateInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.db.Database;
@ -44,18 +43,26 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I
throws CoreException {
super(linkage, parent, function, orig);
final ICPPTemplateInstance asInstance= (ICPPTemplateInstance) function;
final long argListRec= PDOMCPPArgumentList.putArguments(this, asInstance.getTemplateArguments());
final Database db = getDB();
db.putRecPtr(record + ARGUMENTS, argListRec);
long exceptSpecRec = PDOMCPPTypeList.putTypes(this, function.getExceptionSpecification());
db.putRecPtr(record + EXCEPTION_SPEC, exceptSpecRec);
linkage.new ConfigureFunctionInstance(function, this);
}
public PDOMCPPFunctionInstance(PDOMLinkage linkage, long bindingRecord) {
super(linkage, bindingRecord);
}
public void initData(ICPPTemplateArgument[] templateArguments) {
try {
final long argListRec= PDOMCPPArgumentList.putArguments(this, templateArguments);
final Database db = getDB();
db.putRecPtr(record + ARGUMENTS, argListRec);
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
@Override
protected int getRecordSize() {

View file

@ -271,6 +271,22 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
fSpec.initData(fReturnExpression);
}
}
class ConfigureFunctionInstance implements Runnable {
private final PDOMCPPFunctionInstance fInstance;
private final ICPPTemplateArgument[] fTemplateArguments;
public ConfigureFunctionInstance(ICPPFunction original, PDOMCPPFunctionInstance instance) {
fInstance = instance;
fTemplateArguments = ((ICPPTemplateInstance) original).getTemplateArguments();
postProcesses.add(this);
}
@Override
public void run() {
fInstance.initData(fTemplateArguments);
}
}
class ConfigureFunctionTemplate implements Runnable {
private final PDOMCPPFunctionTemplate fTemplate;