1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 358694 - False warning about Unused static function in template

Change-Id: I0ebeef9db921239e896983c68e5291316209c2d2
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
Reviewed-on: https://git.eclipse.org/r/14680
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:
Nathan Ridge 2013-07-18 21:05:13 -04:00 committed by Sergey Prigogin
parent 82d19e7096
commit e18ad3974c
4 changed files with 59 additions and 1 deletions

View file

@ -48,6 +48,8 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.parser.util.AttributeUtil;
@ -245,6 +247,19 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker {
filterOutByPlainName(externVariableDeclarations, plainName);
filterOutByPlainName(staticVariableDeclarations, plainName);
}
if (binding instanceof ICPPDeferredFunction) {
// Function call inside a template - we don't know which overload(s)
// it might match, so to avoid false positives we consider all
// candidates to be potentially used.
ICPPFunction[] candidates = ((ICPPDeferredFunction) binding).getCandidates();
if (candidates != null) {
for (ICPPFunction candidate : candidates) {
externFunctionDeclarations.remove(candidate);
staticFunctionDefinitions.remove(candidate);
}
}
}
IASTNode parentNode = name.getParent();

View file

@ -327,4 +327,20 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
// static void foo(int) {}
// static void foo(float) {}
//
// template <typename T>
// void bar(T t) {
// foo(t);
// }
//
// int main() {
// bar(0);
// }
public void testOverloadedStaticFunctionUsedInTemplate_bug358694() throws IOException {
loadCodeAndRunCpp(getAboveComment());
checkNoErrors();
}
}

View file

@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2013 Nathan Ridge.
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Nathan Ridge
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
/**
* Represents a reference to a function which cannot be resolved
* because an argument depends on a template parameter.
*
* @since 5.6
*/
public interface ICPPDeferredFunction extends ICPPFunction {
/**
* Returns the candidate functions the reference might resolve to
* after template instantiation.
*/
public ICPPFunction[] getCandidates();
}

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
@ -25,7 +26,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
* Represents a reference to a (member) function (instance), which cannot be resolved because
* an argument depends on a template parameter. A compiler would resolve it during instantiation.
*/
public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPFunction, ICPPComputableFunction {
public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPDeferredFunction, ICPPComputableFunction {
private static final ICPPFunctionType FUNCTION_TYPE=
new CPPFunctionType(ProblemType.UNKNOWN_FOR_EXPRESSION, IType.EMPTY_TYPE_ARRAY);
@ -63,6 +64,7 @@ public class CPPDeferredFunction extends CPPUnknownBinding implements ICPPFuncti
fCandidates = candidates;
}
@Override
public ICPPFunction[] getCandidates() {
return fCandidates;
}