summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-07-08 22:23:22 (EDT)
committer Sergey Prigogin2013-07-09 13:05:16 (EDT)
commitc5b4670184ef9fb62f92cff55e2b6d4c6cf475dd (patch)
treec81446fb38b460c46390d11a909c31e2e1b5fa28
parentdb70bb0f2964bce706b49852bc6e3787d87c4d0a (diff)
downloadorg.eclipse.cdt-c5b4670184ef9fb62f92cff55e2b6d4c6cf475dd.zip
org.eclipse.cdt-c5b4670184ef9fb62f92cff55e2b6d4c6cf475dd.tar.gz
org.eclipse.cdt-c5b4670184ef9fb62f92cff55e2b6d4c6cf475dd.tar.bz2
Bug 400673 - [c++11] Unnecessary warning in class constructor (notrefs/changes/97/14397/2
initialized member) when using "in class member initialization" Change-Id: I4e6af3b0927d44f0bb5417d7788fc9a026f8fb7c Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/14397 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.java6
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java9
2 files changed, 14 insertions, 1 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 8c7b66f..3556fbf 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
@@ -92,7 +92,11 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker {
// Add all class fields
for (IField field : ClassTypeHelper.getDeclaredFields(constructor.getClassOwner(), declaration)) {
if (isSimpleType(field.getType()) && !field.isStatic()) {
- fieldsInConstructor.add(field);
+ // In C++11, a field may have an initial value specified at its declaration.
+ // Such a field does not need to be initialized in the constructor as well.
+ if (field.getInitialValue() == null) {
+ fieldsInConstructor.add(field);
+ }
}
}
}
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 9f7b9eb..08af09e 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
@@ -638,4 +638,13 @@ public class ClassMembersInitializationCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
+
+ // struct A {
+ // A() {};
+ // int x = 0;
+ // };
+ public void testNonstaticDataMemberInitializer_400673() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
}