summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Ferreira2013-05-21 21:24:48 (EDT)
committer Sergey Prigogin2013-05-22 13:19:23 (EDT)
commit20e43a27447564e83d9fd9ccbc44df1197cdd2d8 (patch)
tree43c514ec5a7f8950cfe4c2dc15f79b97acda5124
parent7a1fd480ce59b2eb874c9c56c3a547b95a2aa7ac (diff)
downloadorg.eclipse.cdt-20e43a27447564e83d9fd9ccbc44df1197cdd2d8.zip
org.eclipse.cdt-20e43a27447564e83d9fd9ccbc44df1197cdd2d8.tar.gz
org.eclipse.cdt-20e43a27447564e83d9fd9ccbc44df1197cdd2d8.tar.bz2
Bug 402607 - [c++11] Invalid "member was not initialized warning" withrefs/changes/43/13043/2
delegating constructors Change-Id: I521918be7b8c1dd867b53bd22f7646e610651fb6 Reviewed-on: https://git.eclipse.org/r/13043 Reviewed-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java17
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java22
2 files changed, 39 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java
index 17c4884..b7d2f61 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java
@@ -9,6 +9,7 @@
* Anton Gorenkov - initial implementation
* Marc-Andre Laperle
* Nathan Ridge
+ * Danny Ferreira
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers;
@@ -39,8 +40,10 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
@@ -261,6 +264,20 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker {
return null;
if (constructor.getClassOwner().getKey() == ICompositeType.k_union)
return null;
+ // Skip delegating constructors.
+ for (ICPPASTConstructorChainInitializer memberInitializer : functionDefinition.getMemberInitializers()) {
+ IASTName memberName = memberInitializer.getMemberInitializerId();
+ if (memberName != null) {
+ IBinding memberBinding = memberName.resolveBinding();
+ ICPPClassType classType = null;
+ if (memberBinding instanceof ICPPClassType)
+ classType = (ICPPClassType) memberBinding;
+ else if (memberBinding instanceof ICPPConstructor)
+ classType = ((ICPPConstructor) memberBinding).getClassOwner();
+ if (classType != null && classType.isSameType(constructor.getClassOwner()))
+ return null;
+ }
+ }
return constructor;
}
}
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java
index e318918..3277f79 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java
@@ -9,6 +9,7 @@
* Anton Gorenkov - initial implementation
* Marc-Andre Laperle
* Nathan Ridge
+ * Danny Ferreira
*******************************************************************************/
package org.eclipse.cdt.codan.core.internal.checkers;
@@ -602,4 +603,25 @@ public class ClassMembersInitializationCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
+
+ // struct A {
+ // A(int n) : waldo(n) {}
+ // A() : A(42) {} // warning: "Member 'waldo' was not initialized in this constructor"
+ // int waldo;
+ // };
+ public void testBug402607_delegatingConstructor() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
+ // struct A {
+ // typedef A B;
+ // A(int n) : waldo(n) {}
+ // A() : B(42) {} // warning: "Member 'waldo' was not initialized in this constructor"
+ // int waldo;
+ // };
+ public void testBug402607_delegatingConstructorTypedef() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
}