mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 17:55:39 +02:00
Bug 347462: Detection of implicitly called copy ctor.
This commit is contained in:
parent
8a2d881cbd
commit
fa9ba41575
2 changed files with 40 additions and 1 deletions
|
@ -9402,4 +9402,38 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
public void testMemberAccessForArray_347298() throws Exception {
|
public void testMemberAccessForArray_347298() throws Exception {
|
||||||
parseAndCheckBindings();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3047,7 +3047,12 @@ public class CPPSemantics {
|
||||||
sourceType= new InitializerListType((ICPPASTInitializerList) initClause);
|
sourceType= new InitializerListType((ICPPASTInitializerList) initClause);
|
||||||
}
|
}
|
||||||
if (sourceType != null) {
|
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()) {
|
if (c.converts()) {
|
||||||
ICPPFunction f = c.getUserDefinedConversion();
|
ICPPFunction f = c.getUserDefinedConversion();
|
||||||
if (f instanceof ICPPConstructor)
|
if (f instanceof ICPPConstructor)
|
||||||
|
|
Loading…
Add table
Reference in a new issue