mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 466362 - StackOverflowError involving self-referencing template
definition Change-Id: I101dff395f6e58a6852010419045f583eebd47e8
This commit is contained in:
parent
7215298c66
commit
ac121def1a
13 changed files with 110 additions and 50 deletions
|
@ -5858,17 +5858,17 @@ public class AST2TemplateTests extends AST2TestBase {
|
|||
assertSame(template, inst.getTemplateDefinition());
|
||||
}
|
||||
|
||||
// template<typename T1,typename T2> class A{};
|
||||
// template<typename T1> class A<T1, int>{};
|
||||
// template<typename T2> class A<int, T2>{};
|
||||
// template<typename T1, typename T2> class A {};
|
||||
// template<typename T1> class A<T1, int> {};
|
||||
// template<typename T2> class A<int, T2> {};
|
||||
// template<> class A<int, int>;
|
||||
// A<int, int> fooA();
|
||||
//
|
||||
// template<typename T1,typename T2> class B{};
|
||||
// template<typename T1> class B<T1, int>{};
|
||||
// template<typename T2> class B<int, T2>{};
|
||||
// template<typename T1, typename T2> class B {};
|
||||
// template<typename T1> class B<T1, int> {};
|
||||
// template<typename T2> class B<int, T2> {};
|
||||
// template<> class B<int, int> {};
|
||||
// A<int, int> fooB();
|
||||
// B<int, int> fooB();
|
||||
public void testExplicitSpecializationOfForbiddenAsImplicit_356818() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
|
|
@ -2532,6 +2532,22 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
checkBindings();
|
||||
}
|
||||
|
||||
// template <typename T>
|
||||
// struct A {
|
||||
// static T* get();
|
||||
// };
|
||||
|
||||
// class B {
|
||||
// friend class A<B>;
|
||||
// };
|
||||
//
|
||||
// void test() {
|
||||
// A<B>::get();
|
||||
// }
|
||||
public void testFriendClassSpecialization_466362() throws Exception {
|
||||
checkBindings();
|
||||
}
|
||||
|
||||
// template <typename T>
|
||||
// constexpr T t(T) {
|
||||
// return 0;
|
||||
|
@ -2626,6 +2642,25 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
checkBindings();
|
||||
}
|
||||
|
||||
// // Empty header file
|
||||
|
||||
// typedef unsigned long size_t;
|
||||
//
|
||||
// template <size_t... Is> struct int_pack { typedef int_pack type; };
|
||||
//
|
||||
// template <class Pack, size_t I> struct append;
|
||||
//
|
||||
// template <size_t... Is, size_t I>
|
||||
// struct append<int_pack<Is...>, I> : int_pack<Is..., I> {};
|
||||
//
|
||||
// template <size_t C>
|
||||
// struct make_int_pack : append<typename make_int_pack<C - 1>::type, C - 1> {};
|
||||
//
|
||||
// template <> struct make_int_pack<0> : int_pack<> {};
|
||||
public void testRecursiveInheritance_466362() throws Exception {
|
||||
checkBindings();
|
||||
}
|
||||
|
||||
// template <typename T>
|
||||
// struct Bar {};
|
||||
//
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
/**
|
||||
* This interface represents an instantiation of a function template.
|
||||
* This interface represents an instantiation or an explicit specialization of a function template.
|
||||
*
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2010 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2015 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -14,20 +14,17 @@ package org.eclipse.cdt.core.dom.ast.cpp;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
||||
/**
|
||||
* This interface represents an instantiation of a class or function template.
|
||||
* An instantiated template is a specialization of that template.
|
||||
* This interface represents an instantiation or an explicit specialization of a class or a function template.
|
||||
* The {@link #isExplicitSpecialization()} method is used to distinguish between the two cases.
|
||||
*
|
||||
* An instance of a class template will also implement ICPPClassType and similarly
|
||||
* a function template instance will also implement ICPPFunction (or even ICPPMethod
|
||||
* or ICPPConstructor as appropriate)
|
||||
* An instance of a class template will also implement ICPPClassType and similarly a function template
|
||||
* instance will also implement ICPPFunction (or even ICPPMethod or ICPPConstructor as appropriate).
|
||||
*
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
*/
|
||||
public interface ICPPTemplateInstance extends ICPPSpecialization {
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
/** @since 5.1 */
|
||||
ICPPTemplateInstance[] EMPTY_TEMPLATE_INSTANCE_ARRAY = {};
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
||||
/**
|
||||
* The result of instantiating a class template.
|
||||
* The result of instantiating a class template or an explicit specialization of a class template.
|
||||
*/
|
||||
public class CPPClassInstance extends CPPClassSpecialization implements ICPPTemplateInstance {
|
||||
private final ICPPTemplateArgument[] arguments;
|
||||
|
@ -50,20 +50,25 @@ public class CPPClassInstance extends CPPClassSpecialization implements ICPPTemp
|
|||
|
||||
@Override
|
||||
protected ICPPClassSpecializationScope getSpecializationScope() {
|
||||
// An instance with a declaration has no specialization scope.
|
||||
// An instance with a definition has no specialization scope.
|
||||
checkForDefinition();
|
||||
if (getDefinition() != null)
|
||||
return null;
|
||||
final IASTNode[] decls = getDeclarations();
|
||||
if (decls != null && decls.length > 0 && decls[0] != null)
|
||||
return null;
|
||||
|
||||
return super.getSpecializationScope();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExplicitSpecialization() {
|
||||
return !(getCompositeScope() instanceof ICPPClassSpecializationScope);
|
||||
// An instance with a declaration is an explicit specialization.
|
||||
checkForDefinition();
|
||||
if (getDefinition() != null)
|
||||
return true;
|
||||
final IASTNode[] decls = getDeclarations();
|
||||
if (decls != null && decls.length > 0 && decls[0] != null)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
||||
/**
|
||||
* The instantiation of a function template.
|
||||
* An instantiation or an explicit specialization of a function template.
|
||||
*/
|
||||
public class CPPFunctionInstance extends CPPFunctionSpecialization implements ICPPFunctionInstance {
|
||||
private final ICPPTemplateArgument[] fArguments;
|
||||
|
|
|
@ -83,12 +83,12 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
|
|
|
@ -19,6 +19,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
|
||||
/**
|
||||
* The result of instantiating a class template or an explicit specialization of a class template.
|
||||
*/
|
||||
public class CompositeCPPClassInstance extends CompositeCPPClassSpecialization implements ICPPTemplateInstance {
|
||||
|
||||
public CompositeCPPClassInstance(ICompositesFactory cf, ICPPClassType rbinding) {
|
||||
|
|
|
@ -23,6 +23,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
|||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
|
||||
/**
|
||||
* An instantiation or an explicit specialization of a function template.
|
||||
*/
|
||||
public class CompositeCPPFunctionInstance extends CompositeCPPFunction implements ICPPFunctionInstance {
|
||||
|
||||
public CompositeCPPFunctionInstance(ICompositesFactory cf, ICPPFunction rbinding) {
|
||||
|
|
|
@ -257,14 +257,15 @@ public class PDOM extends PlatformObject implements IPDOM {
|
|||
* CDT 8.6 development (versions not supported on the 8.5.x branch)
|
||||
* 180.0 - Internal types of enumerators, bug 446711.
|
||||
* 180.1 - Storing types of unknown members, bug 447728.
|
||||
* 180.2 - Do not apply significant macros to source files, bug 450888.
|
||||
* 180.2 - Do not apply significant macros to source files, bug 450888. <<CDT 8.6>>
|
||||
*
|
||||
* CDT 8.7 development (versions not supported on the 8.6.x branch)
|
||||
* 181.0 - C function type with varargs, bug 452416.
|
||||
* 182.0 - A flag added to PDOMCPPClassSpecialization, bug 466362.
|
||||
*/
|
||||
private static final int MIN_SUPPORTED_VERSION= version(181, 0);
|
||||
private static final int MAX_SUPPORTED_VERSION= version(181, Short.MAX_VALUE);
|
||||
private static final int DEFAULT_VERSION = version(181, 0);
|
||||
private static final int MIN_SUPPORTED_VERSION= version(182, 0);
|
||||
private static final int MAX_SUPPORTED_VERSION= version(182, Short.MAX_VALUE);
|
||||
private static final int DEFAULT_VERSION = version(182, 0);
|
||||
|
||||
private static int version(int major, int minor) {
|
||||
return (major << 16) + minor;
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Result of instantiating a class template.
|
||||
* The result of instantiating a class template or an explicit specialization of a class template.
|
||||
*/
|
||||
class PDOMCPPClassInstance extends PDOMCPPClassSpecialization implements ICPPTemplateInstance {
|
||||
private static final int ARGUMENTS = PDOMCPPClassSpecialization.RECORD_SIZE + 0;
|
||||
|
@ -101,12 +101,6 @@ class PDOMCPPClassInstance extends PDOMCPPClassSpecialization implements ICPPTem
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasOwnScope() throws CoreException {
|
||||
// An instance with a declaration does not use the original template.
|
||||
return hasDeclaration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExplicitSpecialization() {
|
||||
return !(getCompositeScope() instanceof ICPPClassSpecializationScope);
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecialization.RecursionResolvingBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||
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.dom.IPDOMMemberOwner;
|
||||
|
@ -57,13 +58,16 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization
|
|||
implements ICPPClassSpecialization, IPDOMMemberOwner, IPDOMCPPClassType {
|
||||
private static final int FIRST_BASE = PDOMCPPSpecialization.RECORD_SIZE + 0;
|
||||
private static final int MEMBERLIST = FIRST_BASE + 4;
|
||||
private static final int FINAL = MEMBERLIST + PDOMCPPMemberBlock.RECORD_SIZE; // byte
|
||||
private static final int FLAGS = MEMBERLIST + PDOMCPPMemberBlock.RECORD_SIZE; // byte
|
||||
|
||||
/**
|
||||
* The size in bytes of a PDOMCPPClassSpecialization record in the database.
|
||||
*/
|
||||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = FINAL + 1;
|
||||
protected static final int RECORD_SIZE = FLAGS + 1;
|
||||
|
||||
private static final byte FLAGS_FINAL = 0x01;
|
||||
private static final byte FLAGS_HAS_OWN_SCOPE = 0x02;
|
||||
|
||||
private volatile ICPPClassScope fScope;
|
||||
private ObjectMap specializationMap; // Obtained from the synchronized PDOM cache.
|
||||
|
@ -77,7 +81,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization
|
|||
public PDOMCPPClassSpecialization(PDOMCPPLinkage linkage, PDOMNode parent, ICPPClassType classType,
|
||||
PDOMBinding specialized) throws CoreException {
|
||||
super(linkage, parent, (ICPPSpecialization) classType, specialized);
|
||||
setFinal(classType);
|
||||
setFlags(classType);
|
||||
}
|
||||
|
||||
public PDOMCPPClassSpecialization(PDOMLinkage linkage, long bindingRecord) {
|
||||
|
@ -87,8 +91,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization
|
|||
@Override
|
||||
public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
|
||||
if (newBinding instanceof ICPPClassType) {
|
||||
ICPPClassType ct= (ICPPClassType) newBinding;
|
||||
setFinal(ct);
|
||||
ICPPClassType classType= (ICPPClassType) newBinding;
|
||||
setFlags(classType);
|
||||
super.update(linkage, newBinding);
|
||||
}
|
||||
}
|
||||
|
@ -179,10 +183,6 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization
|
|||
return fScope;
|
||||
}
|
||||
|
||||
protected boolean hasOwnScope() throws CoreException {
|
||||
return hasDefinition();
|
||||
}
|
||||
|
||||
public PDOMCPPBase getFirstBase() throws CoreException {
|
||||
long rec = getDB().getRecPtr(record + FIRST_BASE);
|
||||
return rec != 0 ? new PDOMCPPBase(getLinkage(), rec) : null;
|
||||
|
@ -471,15 +471,37 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization
|
|||
@Override
|
||||
public boolean isFinal() {
|
||||
try {
|
||||
return getDB().getByte(record + FINAL) != 0;
|
||||
} catch (CoreException e){
|
||||
return (getFlags() & FLAGS_FINAL) != 0;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void setFinal(ICPPClassType ct) throws CoreException {
|
||||
getDB().putByte(record + FINAL, (byte) (ct.isFinal() ? 1 : 0));
|
||||
private boolean hasOwnScope() throws CoreException {
|
||||
return (getFlags() & FLAGS_HAS_OWN_SCOPE) != 0;
|
||||
}
|
||||
|
||||
private byte getFlags() throws CoreException {
|
||||
return getDB().getByte(record + FLAGS);
|
||||
}
|
||||
|
||||
private void setFlags(ICPPClassType classType) throws CoreException {
|
||||
byte flags = (byte) ((classType.isFinal() ? FLAGS_FINAL : 0) | (hasOwnScope(classType) ? FLAGS_HAS_OWN_SCOPE : 0));
|
||||
getDB().putByte(record + FLAGS, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given class is an explicit template specialization that has its own definition.
|
||||
*/
|
||||
private static boolean hasOwnScope(ICPPClassType classType) {
|
||||
if (!(classType instanceof ICPPInternalBinding))
|
||||
return false;
|
||||
|
||||
ICPPInternalBinding binding = (ICPPInternalBinding) classType;
|
||||
if (binding.getDefinition() != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Result of instantiating a function template.
|
||||
* An instantiation or an explicit specialization of a function template.
|
||||
*/
|
||||
class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements ICPPFunctionInstance {
|
||||
private static final int ARGUMENTS = PDOMCPPFunctionSpecialization.RECORD_SIZE + 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue