mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-07 18:43:32 +02:00
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>
This commit is contained in:
parent
70743bcc78
commit
77592ee87a
2 changed files with 20 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue