Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorHannes Vogt2018-11-03 17:01:29 -0400
committerNathan Ridge2018-11-06 10:31:06 -0500
commitf9c8f0da020820997c2d2394c07e834a33994aab (patch)
tree3db6d8e879c45e47531bd0856489cf7a67f085d9 /core
parentc3d4f065754188b9873e92c754aed03c3bd2b16d (diff)
downloadorg.eclipse.cdt-f9c8f0da020820997c2d2394c07e834a33994aab.tar.gz
org.eclipse.cdt-f9c8f0da020820997c2d2394c07e834a33994aab.tar.xz
org.eclipse.cdt-f9c8f0da020820997c2d2394c07e834a33994aab.zip
Bug 540676 - Improve parsing of alias templates
- If the argument for a template template paramter is unknown (ICPPUnknownType), don't create a problem. - Ensure that a possible argument-parameter mismatch is caught at template instantiation time. Change-Id: Ief61ef93f9d0c19d043aedb89f1c5e66c0374ef2 Signed-off-by: Hannes Vogt <hannes@havogt.de>
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java40
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java12
2 files changed, 49 insertions, 3 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 e4390872b8..7e5d6696e6 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
@@ -10984,4 +10984,44 @@ public class AST2TemplateTests extends AST2CPPTestBase {
public void testDependentTemplateTemplateArgument_540450() throws Exception {
parseAndCheckBindings();
}
+
+ // struct type{};
+ //
+ // template <template <class> class T1>
+ // using template_template_alias = type;
+ //
+ // template<typename T2>
+ // struct foo{
+ // template <typename T3>
+ // struct apply{};
+ // };
+ //
+ // template <class T4>
+ // using trigger = template_template_alias<foo<T4>::template apply>;
+ public void testAliasTemplateWithTemplateTemplateParameter_540676() throws Exception {
+ parseAndCheckBindings();
+ }
+
+ // struct type{};
+ //
+ // template <template <class, class> class T1> // number of arguments doesn't match
+ // using template_template_alias = type;
+ //
+ // template<typename T2>
+ // struct foo{
+ // template <typename T3>
+ // struct apply{};
+ // };
+ //
+ // template <class T4>
+ // using trigger = template_template_alias<foo<T4>::template apply>;
+ //
+ // using A = trigger<type>;
+ //
+ // template <typename> struct B;
+ // using C = B<A>;
+ public void testInvalidAliasTemplateWithTemplateTemplateParameter_540676() throws Exception {
+ BindingAssertionHelper bh= new AST2AssertionHelper(getAboveComment(), CPP);
+ bh.assertProblem("B<A>", 4);
+ }
}
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 89c30f2a77..12d2321b5f 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
@@ -1629,9 +1629,13 @@ public class CPPTemplates {
IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS);
} else if (args != newArgs) {
IType target = instantiateType(instance.getType(), context);
- CPPTemplateParameterMap map =
- instantiateArgumentMap(instance.getTemplateParameterMap(), context);
- result = new CPPAliasTemplateInstance(template, target, instance.getOwner(), map, newArgs);
+ CPPTemplateParameterMap map = createParameterMap(template, newArgs);
+ if (map == null) {
+ result = (IType) createProblem(template,
+ IProblemBinding.SEMANTIC_INVALID_TEMPLATE_ARGUMENTS);
+ } else {
+ result = new CPPAliasTemplateInstance(template, target, instance.getOwner(), map, newArgs);
+ }
} else {
result = type;
}
@@ -2737,6 +2741,8 @@ public class CPPTemplates {
if (param instanceof ICPPTemplateTemplateParameter) {
IType t= arg.getTypeValue();
+ if (t instanceof ICPPUnknownType)
+ return arg;
while (!(t instanceof ICPPTemplateDefinition)) {
if (t instanceof ICPPClassSpecialization) {
// Undo the effect of specializing a template when the unqualified name

Back to the top