From 0a9a95adcd3ba273c1b67a11483d19d435f2b2f2 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Wed, 7 Mar 2012 01:33:16 -0500 Subject: [PATCH] Bug 368419 - FP in members not initialized in constructor --- .../ClassMembersInitializationChecker.java | 5 ++-- ...ClassMembersInitializationCheckerTest.java | 23 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 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 ca27fa12035..9ba327eb8a5 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Anton Gorenkov + * Copyright (c) 2011, 2012 Anton Gorenkov and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Anton Gorenkov - initial implementation + * Marc-Andre Laperle *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; @@ -113,7 +114,7 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker { if (fBinding instanceof ICPPMethod) { ICPPMethod method = (ICPPMethod)fBinding; ICompositeType constructorOwner = actualConstructorFields.iterator().next().getCompositeTypeOwner(); - if (constructorOwner == method.getClassOwner() && !method.getType().isConst()) { + if (constructorOwner.equals(method.getClassOwner()) && !method.getType().isConst()) { skipCurrentConstructor = true; } } else if (fBinding instanceof ICPPFunction) { 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 90a4334324a..4e86f38be5d 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Anton Gorenkov + * Copyright (c) 2011, 2012 Anton Gorenkov and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Anton Gorenkov - initial implementation + * Marc-Andre Laperle *******************************************************************************/ package org.eclipse.cdt.codan.core.internal.checkers; @@ -476,4 +477,24 @@ public class ClassMembersInitializationCheckerTest extends CheckerTestCase { loadCodeAndRun(getAboveComment()); checkErrorLines(8,9,10,11); } + + // @file:test.h + // class C { + // int field; + // C(); + // void initObject(); + //}; + + // @file:test.cpp + // #include "test.h" + // C::C() { + // initObject(); + // } + public void testBug368419_methodDeclarationInOtherFile() throws Exception { + CharSequence[] code = getContents(2); + loadcode(code[0].toString()); + loadcode(code[1].toString()); + runOnProject(); + checkNoErrors(); + } }