mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-08 09:35:23 +02:00
Bug 299911. Improved propagation of template instantiation context.
This commit is contained in:
parent
ec941362f4
commit
9a709aa4a2
4 changed files with 24 additions and 24 deletions
|
@ -59,11 +59,11 @@ public class ClassTypeHelperTests extends AST2BaseTest {
|
||||||
public void testHasTrivialCopyCtor() throws Exception {
|
public void testHasTrivialCopyCtor() throws Exception {
|
||||||
BindingAssertionHelper helper = getAssertionHelper();
|
BindingAssertionHelper helper = getAssertionHelper();
|
||||||
ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class);
|
ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class);
|
||||||
assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classA));
|
assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classA, null));
|
||||||
ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class);
|
ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class);
|
||||||
assertTrue(ClassTypeHelper.hasTrivialCopyCtor(classB));
|
assertTrue(ClassTypeHelper.hasTrivialCopyCtor(classB, null));
|
||||||
ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class);
|
ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class);
|
||||||
assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classC));
|
assertFalse(ClassTypeHelper.hasTrivialCopyCtor(classC, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct A {
|
// struct A {
|
||||||
|
@ -87,11 +87,11 @@ public class ClassTypeHelperTests extends AST2BaseTest {
|
||||||
public void testHasTrivialDestructor() throws Exception {
|
public void testHasTrivialDestructor() throws Exception {
|
||||||
BindingAssertionHelper helper = getAssertionHelper();
|
BindingAssertionHelper helper = getAssertionHelper();
|
||||||
ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class);
|
ICPPClassType classA = helper.assertNonProblem("A {", 1, ICPPClassType.class);
|
||||||
assertFalse(ClassTypeHelper.hasTrivialDestructor(classA));
|
assertFalse(ClassTypeHelper.hasTrivialDestructor(classA, null));
|
||||||
ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class);
|
ICPPClassType classB = helper.assertNonProblem("B {", 1, ICPPClassType.class);
|
||||||
assertTrue(ClassTypeHelper.hasTrivialDestructor(classB));
|
assertTrue(ClassTypeHelper.hasTrivialDestructor(classB, null));
|
||||||
ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class);
|
ICPPClassType classC = helper.assertNonProblem("C {", 1, ICPPClassType.class);
|
||||||
assertFalse(ClassTypeHelper.hasTrivialDestructor(classC));
|
assertFalse(ClassTypeHelper.hasTrivialDestructor(classC, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct A {
|
// struct A {
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||||
* @since 5.4
|
* @since 5.4
|
||||||
*/
|
*/
|
||||||
public class TypeHelper {
|
public class TypeHelper {
|
||||||
|
|
||||||
// Do not instantiate - all methods are static.
|
// Do not instantiate - all methods are static.
|
||||||
private TypeHelper() {
|
private TypeHelper() {
|
||||||
}
|
}
|
||||||
|
@ -49,8 +48,8 @@ public class TypeHelper {
|
||||||
if (type instanceof ICompositeType) {
|
if (type instanceof ICompositeType) {
|
||||||
if (type instanceof ICPPClassType) {
|
if (type instanceof ICPPClassType) {
|
||||||
ICPPClassType classType = ((ICPPClassType) type);
|
ICPPClassType classType = ((ICPPClassType) type);
|
||||||
if (!ClassTypeHelper.hasTrivialCopyCtor(classType) ||
|
if (!ClassTypeHelper.hasTrivialCopyCtor(classType, ast) ||
|
||||||
!ClassTypeHelper.hasTrivialDestructor(classType)) {
|
!ClassTypeHelper.hasTrivialDestructor(classType, ast)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -870,7 +870,7 @@ public class ClassTypeHelper {
|
||||||
* @param classTarget the class to check
|
* @param classTarget the class to check
|
||||||
* @return <code>true</code> if the class has a trivial copy constructor
|
* @return <code>true</code> if the class has a trivial copy constructor
|
||||||
*/
|
*/
|
||||||
public static boolean hasTrivialCopyCtor(ICPPClassType classTarget) {
|
public static boolean hasTrivialCopyCtor(ICPPClassType classTarget, IASTNode point) {
|
||||||
if (getImplicitCopyCtor(classTarget) == null)
|
if (getImplicitCopyCtor(classTarget) == null)
|
||||||
return false;
|
return false;
|
||||||
if (isPolymorphic(classTarget))
|
if (isPolymorphic(classTarget))
|
||||||
|
@ -879,8 +879,8 @@ public class ClassTypeHelper {
|
||||||
if (base.isVirtual())
|
if (base.isVirtual())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (ICPPClassType baseClass : getAllBases(classTarget, null)) {
|
for (ICPPClassType baseClass : getAllBases(classTarget, point)) {
|
||||||
if (!classTarget.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass))
|
if (!classTarget.isSameType(baseClass) && !hasTrivialCopyCtor(baseClass, point))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (ICPPField field : classTarget.getDeclaredFields()) {
|
for (ICPPField field : classTarget.getDeclaredFields()) {
|
||||||
|
@ -888,7 +888,7 @@ public class ClassTypeHelper {
|
||||||
IType type = field.getType();
|
IType type = field.getType();
|
||||||
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY);
|
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY);
|
||||||
if (type instanceof ICPPClassType && !classTarget.isSameType(type) &&
|
if (type instanceof ICPPClassType && !classTarget.isSameType(type) &&
|
||||||
!hasTrivialCopyCtor((ICPPClassType) type)) {
|
!hasTrivialCopyCtor((ICPPClassType) type, point)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -924,23 +924,24 @@ public class ClassTypeHelper {
|
||||||
* Similar to <code>std::tr1::has_trivial_default_constructor</code>.
|
* Similar to <code>std::tr1::has_trivial_default_constructor</code>.
|
||||||
*
|
*
|
||||||
* @param classTarget the class to check
|
* @param classTarget the class to check
|
||||||
|
* @param point
|
||||||
* @return <code>true</code> if the class has a trivial default constructor
|
* @return <code>true</code> if the class has a trivial default constructor
|
||||||
*/
|
*/
|
||||||
public static boolean hasTrivialDefaultConstructor(ICPPClassType classTarget) {
|
public static boolean hasTrivialDefaultConstructor(ICPPClassType classTarget, IASTNode point) {
|
||||||
for (ICPPConstructor ctor : classTarget.getConstructors()) {
|
for (ICPPConstructor ctor : getConstructors(classTarget, point)) {
|
||||||
if (!ctor.isImplicit() && ctor.getParameters().length == 0)
|
if (!ctor.isImplicit() && ctor.getParameters().length == 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (ICPPClassType baseClass : getAllBases(classTarget, null)) {
|
for (ICPPClassType baseClass : getAllBases(classTarget, null)) {
|
||||||
if (!classTarget.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass))
|
if (!classTarget.isSameType(baseClass) && !hasTrivialDefaultConstructor(baseClass, point))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (ICPPField field : classTarget.getDeclaredFields()) {
|
for (ICPPField field : getDeclaredFields(classTarget, point)) {
|
||||||
if (!field.isStatic()) {
|
if (!field.isStatic()) {
|
||||||
IType type = field.getType();
|
IType type = field.getType();
|
||||||
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY);
|
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY);
|
||||||
if (type instanceof ICPPClassType && !classTarget.isSameType(type) &&
|
if (type instanceof ICPPClassType && !classTarget.isSameType(type) &&
|
||||||
!hasTrivialDefaultConstructor((ICPPClassType) type)) {
|
!hasTrivialDefaultConstructor((ICPPClassType) type, point)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -962,21 +963,21 @@ public class ClassTypeHelper {
|
||||||
* @param classTarget the class to check
|
* @param classTarget the class to check
|
||||||
* @return <code>true</code> if the class has a trivial destructor
|
* @return <code>true</code> if the class has a trivial destructor
|
||||||
*/
|
*/
|
||||||
public static boolean hasTrivialDestructor(ICPPClassType classTarget) {
|
public static boolean hasTrivialDestructor(ICPPClassType classTarget, IASTNode point) {
|
||||||
for (ICPPMethod method : classTarget.getDeclaredMethods()) {
|
for (ICPPMethod method : getDeclaredMethods(classTarget, point)) {
|
||||||
if (method.isDestructor())
|
if (method.isDestructor())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (ICPPClassType baseClass : getAllBases(classTarget, null)) {
|
for (ICPPClassType baseClass : getAllBases(classTarget, null)) {
|
||||||
if (!classTarget.isSameType(baseClass) && !hasTrivialDestructor(baseClass))
|
if (!classTarget.isSameType(baseClass) && !hasTrivialDestructor(baseClass, point))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (ICPPField field : classTarget.getDeclaredFields()) {
|
for (ICPPField field : getDeclaredFields(classTarget, point)) {
|
||||||
if (!field.isStatic()) {
|
if (!field.isStatic()) {
|
||||||
IType type = field.getType();
|
IType type = field.getType();
|
||||||
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY);
|
type = SemanticUtil.getNestedType(type, TDEF | CVTYPE | ARRAY);
|
||||||
if (type instanceof ICPPClassType && !classTarget.isSameType(type) &&
|
if (type instanceof ICPPClassType && !classTarget.isSameType(type) &&
|
||||||
!hasTrivialDestructor((ICPPClassType) type)) {
|
!hasTrivialDestructor((ICPPClassType) type, point)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public final class CPPVariableReadWriteFlags extends VariableReadWriteFlags {
|
||||||
IType type = CPPVisitor.createType(parent);
|
IType type = CPPVisitor.createType(parent);
|
||||||
if (type instanceof ICPPUnknownType ||
|
if (type instanceof ICPPUnknownType ||
|
||||||
type instanceof ICPPClassType &&
|
type instanceof ICPPClassType &&
|
||||||
!ClassTypeHelper.hasTrivialDefaultConstructor((ICPPClassType) type)) {
|
!ClassTypeHelper.hasTrivialDefaultConstructor((ICPPClassType) type, parent)) {
|
||||||
return WRITE;
|
return WRITE;
|
||||||
}
|
}
|
||||||
return super.rwInDeclarator(parent, indirection);
|
return super.rwInDeclarator(parent, indirection);
|
||||||
|
|
Loading…
Add table
Reference in a new issue