summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-01-29 18:48:16 (EST)
committerSergey Prigogin2013-01-29 18:49:17 (EST)
commit524777cfa8cc8e0456727b85d0bcfb71e152ba35 (patch)
tree626cfbbcede78d1129e9acfd978a1887a1f88861
parent69c73ec432fde23f438e83fa93a4940fb30034bf (diff)
downloadorg.eclipse.cdt-524777cfa8cc8e0456727b85d0bcfb71e152ba35.zip
org.eclipse.cdt-524777cfa8cc8e0456727b85d0bcfb71e152ba35.tar.gz
org.eclipse.cdt-524777cfa8cc8e0456727b85d0bcfb71e152ba35.tar.bz2
Bug 397828 - Error involving recursive variadic templaterefs/changes/44/9644/3
Change-Id: I68d1ed4c303fcaf7dd1b74438dc0673444f5fedc Reviewed-on: https://git.eclipse.org/r/9644 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--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java19
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java32
2 files changed, 45 insertions, 6 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 fb687f0..789af2f 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
@@ -4841,6 +4841,25 @@ public class AST2TemplateTests extends AST2TestBase {
ub= bh.assertNonProblem("f(h(args...) + args...)", 1);
}
+ // template <typename... Args>
+ // struct contains_waldo;
+ // template <>
+ // struct contains_waldo<> {
+ // static const bool value = false;
+ // };
+ // template <typename First, typename... Rest>
+ // struct contains_waldo<First, Rest...> {
+ // static const bool value = contains_waldo<Rest...>::value;
+ // };
+ // int main() {
+ // bool b1 = contains_waldo<int>::value;
+ // bool b2 = contains_waldo<int, int>::value;
+ // bool b2 = contains_waldo<int, int, int>::value;
+ // }
+ public void testRecursiveVariadicTemplate_397828() throws Exception {
+ parseAndCheckBindings();
+ }
+
// struct Test {
// void Update() {}
// };
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java
index 8f8328c..eeafbef 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java
@@ -37,7 +37,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
-import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IValue;
@@ -607,15 +606,36 @@ public class TemplateArgumentDeduction {
final ICPPTemplateArgument[] p, final ICPPTemplateArgument[] a, CPPTemplateParameterMap map,
IASTNode point) throws DOMException {
TemplateArgumentDeduction deduct= new TemplateArgumentDeduction(pars, null, map, 0);
- final int len= a.length;
- if (p == null || p.length != len) {
+ if (p == null) {
return false;
}
- for (int j= 0; j < len; j++) {
- if (!deduct.fromTemplateArgument(p[j], a[j], point)) {
- return false;
+ boolean containsPackExpansion= false;
+ for (int j= 0; j < p.length; j++) {
+ if (p[j].isPackExpansion()) {
+ deduct = new TemplateArgumentDeduction(deduct, a.length - j);
+ containsPackExpansion= true;
+ if (j != p.length - 1) {
+ return false; // A pack expansion must be the last argument to the specialization.
+ }
+ ICPPTemplateArgument pattern = p[j].getExpansionPattern();
+ for (int i= j; i < a.length; i++) {
+ if (!deduct.fromTemplateArgument(pattern, a[i], point)) {
+ return false;
+ }
+ deduct.incPackOffset();
+ }
+ break;
+ } else {
+ if (j >= a.length) {
+ return false; // Not enough arguments.
+ }
+ if (!deduct.fromTemplateArgument(p[j], a[j], point)) {
+ return false;
+ }
}
}
+ if (!containsPackExpansion && p.length < a.length)
+ return false; // Too many arguments.
return verifyDeduction(pars, map, false, point);
}