summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-07-18 21:05:13 (EDT)
committerSergey Prigogin2013-07-19 12:54:15 (EDT)
commite18ad3974c64b8f7b84df253cd77ab5dffc824f5 (patch)
treef89f736a731ed35fc3101c7705fd7f7baa0a99ff
parent82d19e7096df1445426a8124b90f8c2307b52d57 (diff)
downloadorg.eclipse.cdt-e18ad3974c64b8f7b84df253cd77ab5dffc824f5.zip
org.eclipse.cdt-e18ad3974c64b8f7b84df253cd77ab5dffc824f5.tar.gz
org.eclipse.cdt-e18ad3974c64b8f7b84df253cd77ab5dffc824f5.tar.bz2
Bug 358694 - False warning about Unused static function in templaterefs/changes/80/14680/3
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>
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java15
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java16
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPDeferredFunction.java25
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java4
4 files changed, 59 insertions, 1 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java
index 37a94f8..db8cd98 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java
@@ -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();
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java
index 4849df4..9b5f3e2 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java
@@ -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();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPDeferredFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPDeferredFunction.java
new file mode 100644
index 0000000..e754c9b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPDeferredFunction.java
@@ -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();
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java
index 6f56b92..db8cc03 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunction.java
@@ -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;
}