mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Bug 402607 - [c++11] Invalid "member was not initialized warning" with
delegating constructors Change-Id: I521918be7b8c1dd867b53bd22f7646e610651fb6 Reviewed-on: https://git.eclipse.org/r/13043 Reviewed-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
7a1fd480ce
commit
20e43a2744
2 changed files with 39 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
||||||
* Anton Gorenkov - initial implementation
|
* Anton Gorenkov - initial implementation
|
||||||
* Marc-Andre Laperle
|
* Marc-Andre Laperle
|
||||||
* Nathan Ridge
|
* Nathan Ridge
|
||||||
|
* Danny Ferreira
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.checkers;
|
package org.eclipse.cdt.codan.internal.checkers;
|
||||||
|
|
||||||
|
@ -39,8 +40,10 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
|
@ -261,6 +264,20 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker {
|
||||||
return null;
|
return null;
|
||||||
if (constructor.getClassOwner().getKey() == ICompositeType.k_union)
|
if (constructor.getClassOwner().getKey() == ICompositeType.k_union)
|
||||||
return null;
|
return null;
|
||||||
|
// Skip delegating constructors.
|
||||||
|
for (ICPPASTConstructorChainInitializer memberInitializer : functionDefinition.getMemberInitializers()) {
|
||||||
|
IASTName memberName = memberInitializer.getMemberInitializerId();
|
||||||
|
if (memberName != null) {
|
||||||
|
IBinding memberBinding = memberName.resolveBinding();
|
||||||
|
ICPPClassType classType = null;
|
||||||
|
if (memberBinding instanceof ICPPClassType)
|
||||||
|
classType = (ICPPClassType) memberBinding;
|
||||||
|
else if (memberBinding instanceof ICPPConstructor)
|
||||||
|
classType = ((ICPPConstructor) memberBinding).getClassOwner();
|
||||||
|
if (classType != null && classType.isSameType(constructor.getClassOwner()))
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
return constructor;
|
return constructor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
* Anton Gorenkov - initial implementation
|
* Anton Gorenkov - initial implementation
|
||||||
* Marc-Andre Laperle
|
* Marc-Andre Laperle
|
||||||
* Nathan Ridge
|
* Nathan Ridge
|
||||||
|
* Danny Ferreira
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.internal.checkers;
|
package org.eclipse.cdt.codan.core.internal.checkers;
|
||||||
|
|
||||||
|
@ -602,4 +603,25 @@ public class ClassMembersInitializationCheckerTest extends CheckerTestCase {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkNoErrors();
|
checkNoErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct A {
|
||||||
|
// A(int n) : waldo(n) {}
|
||||||
|
// A() : A(42) {} // warning: "Member 'waldo' was not initialized in this constructor"
|
||||||
|
// int waldo;
|
||||||
|
// };
|
||||||
|
public void testBug402607_delegatingConstructor() throws Exception {
|
||||||
|
loadCodeAndRun(getAboveComment());
|
||||||
|
checkNoErrors();
|
||||||
|
}
|
||||||
|
|
||||||
|
// struct A {
|
||||||
|
// typedef A B;
|
||||||
|
// A(int n) : waldo(n) {}
|
||||||
|
// A() : B(42) {} // warning: "Member 'waldo' was not initialized in this constructor"
|
||||||
|
// int waldo;
|
||||||
|
// };
|
||||||
|
public void testBug402607_delegatingConstructorTypedef() throws Exception {
|
||||||
|
loadCodeAndRun(getAboveComment());
|
||||||
|
checkNoErrors();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue