mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
Bug 404774 - Invalid implicit ctor call is not marked as error
This commit is contained in:
parent
f987bfe27c
commit
cc82847af6
2 changed files with 32 additions and 18 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010, 2011 Marc-Andre Laperle and others.
|
||||
* Copyright (c) 2010, 2013 Marc-Andre Laperle 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
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Marc-Andre Laperle - Initial API and implementation
|
||||
* Tomasz Wesolowski - Extension for fixes
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.internal.checkers;
|
||||
|
||||
|
@ -25,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -32,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
|
@ -74,6 +77,7 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
|||
ast.accept(new ASTVisitor() {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
shouldVisitImplicitNames = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,7 +86,7 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
|||
IBinding binding = name.resolveBinding();
|
||||
if (binding instanceof IProblemBinding) {
|
||||
IASTNode parentNode = name.getParent();
|
||||
// Don't report multiple problems with qualified names
|
||||
// Don't report multiple problems with qualified names.
|
||||
if (parentNode instanceof ICPPASTQualifiedName) {
|
||||
if (((ICPPASTQualifiedName) parentNode).resolveBinding() instanceof IProblemBinding)
|
||||
return PROCESS_CONTINUE;
|
||||
|
@ -137,11 +141,11 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
// From this point, we'll deal only with NAME_NOT_FOUND problems.
|
||||
// If it's something else continue because we don't want to give bad messages
|
||||
// If it's something else continue because we don't want to give bad messages.
|
||||
if (id != IProblemBinding.SEMANTIC_NAME_NOT_FOUND) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
if (isFunctionCall(parentNode)) {
|
||||
if (isFunctionCall(name, parentNode)) {
|
||||
handleFunctionProblem(name, problemBinding, contextFlagsString);
|
||||
} else if (parentNode instanceof IASTFieldReference) {
|
||||
handleMemberProblem(name, parentNode, problemBinding, contextFlagsString);
|
||||
|
@ -227,14 +231,16 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
|||
reportProblem(ERR_ID_VariableResolutionProblem, name, name.getBinding().getName(), contextFlagsString, name.getRawSignature());
|
||||
}
|
||||
|
||||
private boolean isFunctionCall(IASTNode parentNode) {
|
||||
private boolean isFunctionCall(IASTName name, IASTNode parentNode) {
|
||||
if (parentNode instanceof IASTIdExpression) {
|
||||
IASTIdExpression expression = (IASTIdExpression) parentNode;
|
||||
IASTNode parentParentNode = expression.getParent();
|
||||
if (parentParentNode instanceof IASTFunctionCallExpression
|
||||
&& expression.getPropertyInParent().getName().equals(IASTFunctionCallExpression.FUNCTION_NAME.getName())) {
|
||||
&& expression.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
|
||||
return true;
|
||||
}
|
||||
} else if (parentNode instanceof ICPPASTDeclarator && name instanceof IASTImplicitName) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -280,8 +286,7 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a string of the function signature : returntype + function +
|
||||
* parameters
|
||||
* Returns a string of the function signature : returntype + function + parameters
|
||||
*
|
||||
* @param functionBinding The function to get the signature
|
||||
* @return A string of the function signature
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2011 Marc-Andre Laperle and others.
|
||||
* Copyright (c) 2011, 2013 Marc-Andre Laperle 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:
|
||||
* Marc-Andre Laperle - Initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.internal.checkers;
|
||||
|
||||
|
@ -20,15 +21,11 @@ public class ProblemBindingCheckerTest extends CheckerTestCase {
|
|||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.test.CodanTestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
enableProblems(ProblemBindingChecker.ERR_ID_AmbiguousProblem, ProblemBindingChecker.ERR_ID_Candidates,
|
||||
enableProblems(
|
||||
ProblemBindingChecker.ERR_ID_AmbiguousProblem, ProblemBindingChecker.ERR_ID_Candidates,
|
||||
ProblemBindingChecker.ERR_ID_CircularReferenceProblem, ProblemBindingChecker.ERR_ID_FieldResolutionProblem,
|
||||
ProblemBindingChecker.ERR_ID_FunctionResolutionProblem, ProblemBindingChecker.ERR_ID_InvalidArguments,
|
||||
ProblemBindingChecker.ERR_ID_InvalidTemplateArgumentsProblem, ProblemBindingChecker.ERR_ID_LabelStatementNotFoundProblem,
|
||||
|
@ -42,11 +39,23 @@ public class ProblemBindingCheckerTest extends CheckerTestCase {
|
|||
// struct X {} x;
|
||||
// fun(x.y);
|
||||
// }
|
||||
public void testBug338683FieldInFunctionCall() {
|
||||
public void testFieldInFunctionCall_338683() {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkErrorLine(3, ProblemBindingChecker.ERR_ID_FieldResolutionProblem);
|
||||
}
|
||||
|
||||
// struct A {
|
||||
// A(int x, int y);
|
||||
// };
|
||||
//
|
||||
// void test() {
|
||||
// A a("hi", 1, 2);
|
||||
// }
|
||||
public void testImplicitConstructorCall_404774() {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkErrorLine(6, ProblemBindingChecker.ERR_ID_InvalidArguments);
|
||||
}
|
||||
|
||||
// int main () {
|
||||
// struct X {} x;
|
||||
// x.b(
|
||||
|
@ -61,7 +70,7 @@ public class ProblemBindingCheckerTest extends CheckerTestCase {
|
|||
// x.y,
|
||||
// a.b()))));
|
||||
// }
|
||||
public void testBug338683VariousFieldMethodCombinations() {
|
||||
public void testVariousFieldMethodCombinations_338683() {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkErrorLine(3, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
|
||||
checkErrorLine(4, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
|
||||
|
@ -81,7 +90,7 @@ public class ProblemBindingCheckerTest extends CheckerTestCase {
|
|||
// MACRO(foo());
|
||||
// return 0;
|
||||
// }
|
||||
public void testBug341089DontUnderlineWholeMacro() {
|
||||
public void testDontUnderlineWholeMacro_341089() {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
IMarker marker = checkErrorLine(3, ProblemBindingChecker.ERR_ID_FunctionResolutionProblem);
|
||||
assertFalse(marker.getAttribute(IMarker.MESSAGE, "").contains("MACRO")); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
|
Loading…
Add table
Reference in a new issue