mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 347462: Detection of implicitly called copy ctor.
This commit is contained in:
parent
70b1c522bd
commit
be01bfb2ce
2 changed files with 39 additions and 1 deletions
|
@ -9391,4 +9391,37 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertTrue(qn.isDeclaration());
|
assertTrue(qn.isDeclaration());
|
||||||
assertTrue(qn.getLastName().isDeclaration());
|
assertTrue(qn.getLastName().isDeclaration());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3111,7 +3111,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