Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-04-07 04:26:15 -0400
committerMarco Stornelli2019-04-07 04:26:15 -0400
commit77592ee87ac41d54f18715892fa8090c7245c53a (patch)
treed85bddb2b4f0f5cee098893888e35fcc867de2a2
parent70743bcc784e0df450564f68b15adf07d74b9233 (diff)
downloadorg.eclipse.cdt-77592ee87ac41d54f18715892fa8090c7245c53a.tar.gz
org.eclipse.cdt-77592ee87ac41d54f18715892fa8090c7245c53a.tar.xz
org.eclipse.cdt-77592ee87ac41d54f18715892fa8090c7245c53a.zip
Bug 546179 - Fix lack of warning for field references
With just a reference of the field even for another instance of the same class the warning wasn't provided to the user. Change-Id: Icb6ca008c2e61b8a762ecf31e4514cb0368c477d Signed-off-by: Marco Stornelli <marco.stornelli@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.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java14
2 files changed, 20 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 6542744abc..346e13d2de 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
@@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
@@ -199,6 +200,11 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker {
@Override
public int visit(IASTName name) {
if (!constructorsStack.empty()) {
+ if (name.getParent() instanceof IASTFieldReference) {
+ IASTFieldReference ref = (IASTFieldReference) name.getParent();
+ if (!referencesThis(ref.getFieldOwner()))
+ return PROCESS_CONTINUE;
+ }
Set<IField> actualConstructorFields = constructorsStack.peek();
if (!actualConstructorFields.isEmpty()) {
IBinding binding = name.resolveBinding();
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java
index 906dbbbb91..6720667706 100644
--- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ClassMembersInitializationCheckerTest.java
@@ -685,4 +685,18 @@ public class ClassMembersInitializationCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
+
+ // class Waldo {
+ // private:
+ // int location;
+ // public:
+ // Waldo() {
+ // Waldo d;
+ // d.location = 1;
+ // }
+ // };
+ public void testOtherInstance_Bug519473() throws Exception {
+ loadCodeAndRun(getAboveComment());
+ checkErrorLine(5);
+ }
}

Back to the top