1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 17:25:38 +02:00

Bug 347462: Detection of implicitly called copy ctor.

This commit is contained in:
Markus Schorn 2011-07-01 14:47:03 +02:00
parent 8a2d881cbd
commit fa9ba41575
2 changed files with 40 additions and 1 deletions

View file

@ -9402,4 +9402,38 @@ public class AST2CPPTests extends AST2BaseTest {
public void testMemberAccessForArray_347298() throws Exception {
parseAndCheckBindings();
}
// struct X {};
// struct Y : X {
// Y(){}
// Y(Y const & y){}
// };
// void test() {
// Y y;
// Y y2 = y;
// X x = y2;
// }
public void testReferenceToCopyConstructor() throws Exception {
IASTTranslationUnit tu= parseAndCheckBindings();
ICPPASTFunctionDefinition fdef= getDeclaration(tu, 2);
IASTDeclarationStatement dst= getStatement(fdef, 0);
IASTDeclarator dtor= ((IASTSimpleDeclaration) dst.getDeclaration()).getDeclarators()[0];
IBinding ctor= ((IASTImplicitNameOwner) dtor).getImplicitNames()[0].resolveBinding();
assertTrue(ctor instanceof ICPPConstructor);
assertEquals(0, ((ICPPConstructor) ctor).getType().getParameterTypes().length);
dst= getStatement(fdef, 1);
dtor= ((IASTSimpleDeclaration) dst.getDeclaration()).getDeclarators()[0];
ctor= ((IASTImplicitNameOwner) dtor).getImplicitNames()[0].resolveBinding();
assertTrue(ctor instanceof ICPPConstructor);
assertEquals(1, ((ICPPConstructor) ctor).getType().getParameterTypes().length);
dst= getStatement(fdef, 2);
dtor= ((IASTSimpleDeclaration) dst.getDeclaration()).getDeclarators()[0];
ctor= ((IASTImplicitNameOwner) dtor).getImplicitNames()[0].resolveBinding();
assertTrue(ctor instanceof ICPPConstructor);
assertEquals(1, ((ICPPConstructor) ctor).getType().getParameterTypes().length);
}
}

View file

@ -3047,7 +3047,12 @@ public class CPPSemantics {
sourceType= new InitializerListType((ICPPASTInitializerList) initClause);
}
if (sourceType != null) {
Cost c= Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY);
Cost c;
if (calculateInheritanceDepth(sourceType, classType) >= 0) {
c = Conversions.copyInitializationOfClass(isLValue, sourceType, classType, false);
} else {
c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY);
}
if (c.converts()) {
ICPPFunction f = c.getUserDefinedConversion();
if (f instanceof ICPPConstructor)