Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2014-08-10 06:48:09 +0000
committerSergey Prigogin2014-08-11 17:33:27 +0000
commit3e540156b67bc3ee8658e54646057fedf1daaf14 (patch)
tree63c10a74e0ae3a9d40911d8983ca31be970cedc2
parent42235704cb6742c32119f12580bb486107140282 (diff)
downloadorg.eclipse.cdt-3e540156b67bc3ee8658e54646057fedf1daaf14.tar.gz
org.eclipse.cdt-3e540156b67bc3ee8658e54646057fedf1daaf14.tar.xz
org.eclipse.cdt-3e540156b67bc3ee8658e54646057fedf1daaf14.zip
Bug 404245 - Check that a function call has enough arguments after
template argument deduction Change-Id: I2824e908dc6ea9796c9400e81f3ef34d97406dc6 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/31345 Tested-by: Hudson CI Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java13
4 files changed, 28 insertions, 5 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
index 7c44be0b953..31e3a6fa056 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
@@ -8047,6 +8047,17 @@ public class AST2TemplateTests extends AST2TestBase {
parseAndCheckBindings();
}
+ // template <typename... Args>
+ // void waldo(Args...);
+ //
+ // int main() {
+ // waldo<int>();
+ // }
+ public void testExplicitArgumentsForParameterPack_404245() throws Exception {
+ BindingAssertionHelper helper = getAssertionHelper();
+ helper.assertProblem("waldo<int>()", "waldo<int>");
+ }
+
// template <typename T>
// struct A {};
//
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
index 12a5d5c201a..0ad6f654d7d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
@@ -654,7 +654,10 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
@Override
public boolean hasParameterPack() {
- ICPPParameter[] pars= getParameters();
+ return hasParameterPack(getParameters());
+ }
+
+ public static boolean hasParameterPack(ICPPParameter[] pars) {
return pars.length > 0 && pars[pars.length - 1].isParameterPack();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java
index d2e1f13c2ae..72e6cfadb14 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java
@@ -69,12 +69,12 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
@Override
public int getRequiredArgumentCount() {
- return ((ICPPFunction) getSpecializedBinding()).getRequiredArgumentCount();
+ return CPPFunction.getRequiredArgumentCount(getParameters());
}
@Override
public boolean hasParameterPack() {
- return ((ICPPFunction) getSpecializedBinding()).hasParameterPack();
+ return CPPFunction.hasParameterPack(getParameters());
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
index f05489611ab..71ceff23b34 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
@@ -2041,8 +2041,17 @@ public class CPPTemplates {
IBinding instance= instantiateFunctionTemplate(template, args, map, point);
if (instance instanceof ICPPFunction) {
final ICPPFunction f = (ICPPFunction) instance;
- if (SemanticUtil.isValidType(f.getType()))
- return f;
+ if (SemanticUtil.isValidType(f.getType())) {
+ // The number of arguments have been checked against the function
+ // template's required argument count at an earlier stage. However,
+ // the process of instantiation can increase the required argument
+ // count by expanding parameter packs. If arguments are provided
+ // for a parameter pack explicitly, it's possible for deduction to
+ // succeed without having enough function arguments to match a
+ // corresponding function parameter pack - so we check again.
+ if (fnArgs.size() >= f.getRequiredArgumentCount())
+ return f;
+ }
}
}
} catch (DOMException e) {

Back to the top