summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-07-08 22:23:22 (EDT)
committer Sergey Prigogin2013-07-17 14:45:25 (EDT)
commite876bb04f2bbb12a792558a626e76147b10c7365 (patch)
tree266404345ef109d304eb2c48fcd8ce2a7680c1a0
parent0d801f0615628fa3e1f6b6887a3b6d188a8cbfa9 (diff)
downloadorg.eclipse.cdt-e876bb04f2bbb12a792558a626e76147b10c7365.zip
org.eclipse.cdt-e876bb04f2bbb12a792558a626e76147b10c7365.tar.gz
org.eclipse.cdt-e876bb04f2bbb12a792558a626e76147b10c7365.tar.bz2
Bug 400673 - [c++11] Unnecessary warning in class constructor (not
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();
+ }
}