1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

Bug 404774 - Invalid implicit ctor call is not marked as error

This commit is contained in:
Sergey Prigogin 2013-04-02 23:48:43 -07:00
parent f987bfe27c
commit cc82847af6
2 changed files with 32 additions and 18 deletions

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Marc-Andre Laperle - Initial API and implementation * Marc-Andre Laperle - Initial API and implementation
* Tomasz Wesolowski - Extension for fixes * Tomasz Wesolowski - Extension for fixes
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers; 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.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; 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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode; 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.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; 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.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@ -74,6 +77,7 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
ast.accept(new ASTVisitor() { ast.accept(new ASTVisitor() {
{ {
shouldVisitNames = true; shouldVisitNames = true;
shouldVisitImplicitNames = true;
} }
@Override @Override
@ -82,7 +86,7 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
IBinding binding = name.resolveBinding(); IBinding binding = name.resolveBinding();
if (binding instanceof IProblemBinding) { if (binding instanceof IProblemBinding) {
IASTNode parentNode = name.getParent(); 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 (parentNode instanceof ICPPASTQualifiedName) {
if (((ICPPASTQualifiedName) parentNode).resolveBinding() instanceof IProblemBinding) if (((ICPPASTQualifiedName) parentNode).resolveBinding() instanceof IProblemBinding)
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
@ -137,11 +141,11 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
// From this point, we'll deal only with NAME_NOT_FOUND problems. // 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) { if (id != IProblemBinding.SEMANTIC_NAME_NOT_FOUND) {
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
if (isFunctionCall(parentNode)) { if (isFunctionCall(name, parentNode)) {
handleFunctionProblem(name, problemBinding, contextFlagsString); handleFunctionProblem(name, problemBinding, contextFlagsString);
} else if (parentNode instanceof IASTFieldReference) { } else if (parentNode instanceof IASTFieldReference) {
handleMemberProblem(name, parentNode, problemBinding, contextFlagsString); 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()); 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) { if (parentNode instanceof IASTIdExpression) {
IASTIdExpression expression = (IASTIdExpression) parentNode; IASTIdExpression expression = (IASTIdExpression) parentNode;
IASTNode parentParentNode = expression.getParent(); IASTNode parentParentNode = expression.getParent();
if (parentParentNode instanceof IASTFunctionCallExpression if (parentParentNode instanceof IASTFunctionCallExpression
&& expression.getPropertyInParent().getName().equals(IASTFunctionCallExpression.FUNCTION_NAME.getName())) { && expression.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
return true; return true;
} }
} else if (parentNode instanceof ICPPASTDeclarator && name instanceof IASTImplicitName) {
return true;
} }
return false; return false;
} }
@ -280,8 +286,7 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
} }
/** /**
* Returns a string of the function signature : returntype + function + * Returns a string of the function signature : returntype + function + parameters
* parameters
* *
* @param functionBinding The function to get the signature * @param functionBinding The function to get the signature
* @return A string of the function signature * @return A string of the function signature

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Marc-Andre Laperle - Initial API and implementation * Marc-Andre Laperle - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.core.internal.checkers; package org.eclipse.cdt.codan.core.internal.checkers;
@ -20,15 +21,11 @@ public class ProblemBindingCheckerTest extends CheckerTestCase {
return true; return true;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.codan.core.test.CodanTestCase#setUp()
*/
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); 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_CircularReferenceProblem, ProblemBindingChecker.ERR_ID_FieldResolutionProblem,
ProblemBindingChecker.ERR_ID_FunctionResolutionProblem, ProblemBindingChecker.ERR_ID_InvalidArguments, ProblemBindingChecker.ERR_ID_FunctionResolutionProblem, ProblemBindingChecker.ERR_ID_InvalidArguments,
ProblemBindingChecker.ERR_ID_InvalidTemplateArgumentsProblem, ProblemBindingChecker.ERR_ID_LabelStatementNotFoundProblem, ProblemBindingChecker.ERR_ID_InvalidTemplateArgumentsProblem, ProblemBindingChecker.ERR_ID_LabelStatementNotFoundProblem,
@ -42,11 +39,23 @@ public class ProblemBindingCheckerTest extends CheckerTestCase {
// struct X {} x; // struct X {} x;
// fun(x.y); // fun(x.y);
// } // }
public void testBug338683FieldInFunctionCall() { public void testFieldInFunctionCall_338683() {
loadCodeAndRun(getAboveComment()); loadCodeAndRun(getAboveComment());
checkErrorLine(3, ProblemBindingChecker.ERR_ID_FieldResolutionProblem); 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 () { // int main () {
// struct X {} x; // struct X {} x;
// x.b( // x.b(
@ -61,7 +70,7 @@ public class ProblemBindingCheckerTest extends CheckerTestCase {
// x.y, // x.y,
// a.b())))); // a.b()))));
// } // }
public void testBug338683VariousFieldMethodCombinations() { public void testVariousFieldMethodCombinations_338683() {
loadCodeAndRun(getAboveComment()); loadCodeAndRun(getAboveComment());
checkErrorLine(3, ProblemBindingChecker.ERR_ID_MethodResolutionProblem); checkErrorLine(3, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
checkErrorLine(4, ProblemBindingChecker.ERR_ID_MethodResolutionProblem); checkErrorLine(4, ProblemBindingChecker.ERR_ID_MethodResolutionProblem);
@ -81,7 +90,7 @@ public class ProblemBindingCheckerTest extends CheckerTestCase {
// MACRO(foo()); // MACRO(foo());
// return 0; // return 0;
// } // }
public void testBug341089DontUnderlineWholeMacro() { public void testDontUnderlineWholeMacro_341089() {
loadCodeAndRun(getAboveComment()); loadCodeAndRun(getAboveComment());
IMarker marker = checkErrorLine(3, ProblemBindingChecker.ERR_ID_FunctionResolutionProblem); IMarker marker = checkErrorLine(3, ProblemBindingChecker.ERR_ID_FunctionResolutionProblem);
assertFalse(marker.getAttribute(IMarker.MESSAGE, "").contains("MACRO")); //$NON-NLS-1$//$NON-NLS-2$ assertFalse(marker.getAttribute(IMarker.MESSAGE, "").contains("MACRO")); //$NON-NLS-1$//$NON-NLS-2$