summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-01-29 19:22:40 (EST)
committerSergey Prigogin2013-01-29 19:41:48 (EST)
commit95c12313366888fea38f77449ef4ba840f52ac1b (patch)
treef68603dae69c0866df79a2458272de926888cb4e
parentd4cf62a7853199a723b45d6454586e67ae3332c4 (diff)
downloadorg.eclipse.cdt-95c12313366888fea38f77449ef4ba840f52ac1b.zip
org.eclipse.cdt-95c12313366888fea38f77449ef4ba840f52ac1b.tar.gz
org.eclipse.cdt-95c12313366888fea38f77449ef4ba840f52ac1b.tar.bz2
Bug 399039 - Error involving variadic non-type template parameterrefs/changes/43/9943/4
Change-Id: I61b19e1fc5aac9372ad756c1e33e412f4bee86e2 Reviewed-on: https://git.eclipse.org/r/9943 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.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java9
4 files changed, 59 insertions, 4 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 f1ef857..f6f6649 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
@@ -7069,6 +7069,33 @@ public class AST2TemplateTests extends AST2TestBase {
parseAndCheckBindings();
}
+ // template <bool...>
+ // struct ice_or {
+ // static const bool value = false;
+ // };
+ // template <typename T>
+ // struct is_foo {
+ // static const bool value = false;
+ // };
+ // template <typename... Args>
+ // struct contains_foo {
+ // static const bool value = ice_or<is_foo<Args>::value...>::value;
+ // };
+ // template <bool>
+ // struct meta;
+ // struct S { void bar(); };
+ // template <>
+ // struct meta<false> {
+ // typedef S type;
+ // };
+ // int main() {
+ // meta<contains_foo<>::value>::type t;
+ // t.bar();
+ // }
+ public void testVariadicNonTypeTemplateParameter_399039() throws Exception {
+ parseAndCheckBindings();
+ }
+
// template <typename...>
// struct common_type;
// template <typename T>
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java
index 0ed1f67..4bff763 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. and others.
+ * Copyright (c) 2012, 2013 Wind River Systems, Inc. and others.
* 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
@@ -8,6 +8,7 @@
* Contributors:
* Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
+ * Nathan Ridge
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -84,8 +85,16 @@ public interface ICPPEvaluation extends ISerializableEvaluation {
IASTNode point);
/**
- * Determines size of the template parameter pack.
+ * Searches the evaluation for a usage of a template parameter which is a parameter pack,
+ * and returns the number of arguments bound to that parameter pack in the given
+ * template parameter map.
*
+ * Can also return one of the special values CPPTemplates.PACK_SIZE_DEFER,
+ * CPPTemplates.PACK_SIZE_FAIL, and CPPTemplates.PACK_SIZE_NOT_FOUND. See their
+ * declarations for their meanings.
+ *
+ * See also CPPTemplates.determinePackSize().
+ *
* @noreference This method is not intended to be referenced by clients.
*/
int determinePackSize(ICPPTemplateParameterMap tpMap);
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 8d4f25c..9e4a6d0 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
@@ -162,9 +162,23 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMod
* type instantiation.
*/
public class CPPTemplates {
+ // The three constants below are used as special return values for the various overloads
+ // of CPPTemplates.determinePackSize() and for ICPPEvaluation.determinePackSize(), which
+ // search a type, template argument, or value for a usage of a template parameter pack
+ // and return the number of arguments bound to that parameter pack in an
+ // ICPPTemplateParameterMap.
+
+ // Used to indicate that the parameter pack is not bound to any arguments in the
+ // template parameter map. Computation of the pack size needs to be deferred until
+ // arguments for it become available.
static final int PACK_SIZE_DEFER = -1;
+
+ // Used to indicate that two different packs with different sizes were found.
static final int PACK_SIZE_FAIL = -2;
+
+ // Used to indicate that no template parameter packs were found.
static final int PACK_SIZE_NOT_FOUND = Integer.MAX_VALUE;
+
static enum TypeSelection { PARAMETERS, RETURN_TYPE, PARAMETERS_AND_RETURN_TYPE }
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java
index 7476070..61c5c78 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java
@@ -360,8 +360,13 @@ public class EvalID extends CPPEvaluation {
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
int r = fFieldOwner != null ? fFieldOwner.determinePackSize(tpMap) : CPPTemplates.PACK_SIZE_NOT_FOUND;
- for (ICPPTemplateArgument arg : fTemplateArgs) {
- r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap));
+ if (fNameOwner instanceof ICPPUnknownBinding) {
+ r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize((ICPPUnknownBinding) fNameOwner, tpMap));
+ }
+ if (fTemplateArgs != null) {
+ for (ICPPTemplateArgument arg : fTemplateArgs) {
+ r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap));
+ }
}
return r;
}