Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarkus Schorn2011-07-01 08:47:03 -0400
committerMarkus Schorn2011-07-04 04:16:24 -0400
commitfa9ba41575574c1e78b6b4519eff27363a4fe5e3 (patch)
tree4f444fa735ab682509e83e9b4b08652e942b7606 /core
parent8a2d881cbd0bd748150f6791cfdc941632e6e016 (diff)
downloadorg.eclipse.cdt-fa9ba41575574c1e78b6b4519eff27363a4fe5e3.tar.gz
org.eclipse.cdt-fa9ba41575574c1e78b6b4519eff27363a4fe5e3.tar.xz
org.eclipse.cdt-fa9ba41575574c1e78b6b4519eff27363a4fe5e3.zip
Bug 347462: Detection of implicitly called copy ctor.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java34
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java7
2 files changed, 40 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index 93a0582d0c..81d470ebc7 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -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);
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
index c7b538a33e..4d744a4a26 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
@@ -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)

Back to the top