1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 512789 - Guard against infinite recursion in TypeTraits.hasTrivialDefaultConstructor()

The infinite recursion could happen if an inheritance hierarchy has a
cycle in it, or if a class aggregates itself (both of which are invalid).

Change-Id: I99598a57982dca51acab5a1297392f04d9008aec
This commit is contained in:
Nathan Ridge 2017-04-26 01:23:19 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 32c2e14b80
commit 917061f98a
2 changed files with 7 additions and 4 deletions

View file

@ -67,7 +67,7 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags {
IType type = CPPVisitor.createType(parent);
if (type instanceof ICPPUnknownType ||
type instanceof ICPPClassType &&
!TypeTraits.hasTrivialDefaultConstructor((ICPPClassType) type, parent)) {
!TypeTraits.hasTrivialDefaultConstructor((ICPPClassType) type, parent, CPPSemantics.MAX_INHERITANCE_DEPTH)) {
return WRITE;
}
return super.rwInDeclarator(parent, indirection);

View file

@ -346,13 +346,16 @@ public class TypeTraits {
* @param point
* @return {@code true} if the class has a trivial default constructor
*/
public static boolean hasTrivialDefaultConstructor(ICPPClassType classType, IASTNode point) {
public static boolean hasTrivialDefaultConstructor(ICPPClassType classType, IASTNode point, int maxdepth) {
if (maxdepth <= 0) {
return false;
}
for (ICPPConstructor ctor : ClassTypeHelper.getConstructors(classType, point)) {
if (!ctor.isImplicit() && ctor.getParameters().length == 0)
return false;
}
for (ICPPClassType baseClass : ClassTypeHelper.getAllBases(classType, null)) {
if (!classType.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass, point))
if (!classType.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass, point, maxdepth - 1))
return false;
}
for (ICPPField field : ClassTypeHelper.getDeclaredFields(classType, point)) {
@ -360,7 +363,7 @@ public class TypeTraits {
IType type = field.getType();
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY);
if (type instanceof ICPPClassType && !classType.isSameType(type) &&
!hasTrivialDefaultConstructor((ICPPClassType) type, point)) {
!hasTrivialDefaultConstructor((ICPPClassType) type, point, maxdepth - 1)) {
return false;
}
}