Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Morgner2018-11-14 09:26:59 +0000
committerMarco Stornelli2020-03-13 07:35:34 +0000
commitbcb955a32104da02f3748dd3ef080cbcb43c646b (patch)
tree3cd7a84dd8ae93796adae1ebd3394e880eaa269e /core/org.eclipse.cdt.core.tests
parent5823d56a2d15c0719fb33b23cb1197af3a7ba71c (diff)
downloadorg.eclipse.cdt-bcb955a32104da02f3748dd3ef080cbcb43c646b.tar.gz
org.eclipse.cdt-bcb955a32104da02f3748dd3ef080cbcb43c646b.tar.xz
org.eclipse.cdt-bcb955a32104da02f3748dd3ef080cbcb43c646b.zip
541239: [C++17] Implement parser support for deduction guides
Change-Id: I1683583af981d276b346ba8470a9044cfd8921cd Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=541239 Signed-off-by: Felix Morgner <fmorgner@hsr.ch> Also-by: Marco Stornelli <marco.stornelli@gmail.com>
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java2
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/DeductionGuideTests.java187
2 files changed, 189 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java
index 5f17ae73f30..f1fe6b37975 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java
@@ -20,6 +20,7 @@ import org.eclipse.cdt.core.parser.tests.ast2.cxx14.GenericLambdaTests;
import org.eclipse.cdt.core.parser.tests.ast2.cxx14.InitCaptureTests;
import org.eclipse.cdt.core.parser.tests.ast2.cxx14.ReturnTypeDeductionTests;
import org.eclipse.cdt.core.parser.tests.ast2.cxx14.VariableTemplateTests;
+import org.eclipse.cdt.core.parser.tests.ast2.cxx17.DeductionGuideTests;
import org.eclipse.cdt.core.parser.tests.ast2.cxx17.LambdaExpressionTests;
import org.eclipse.cdt.core.parser.tests.ast2.cxx17.StructuredBindingTests;
import org.eclipse.cdt.core.parser.tests.ast2.cxx17.TemplateAutoTests;
@@ -76,6 +77,7 @@ public class DOMParserTestSuite extends TestCase {
suite.addTest(TemplateAutoTests.suite());
suite.addTestSuite(LambdaExpressionTests.class);
suite.addTestSuite(StructuredBindingTests.class);
+ suite.addTestSuite(DeductionGuideTests.class);
return suite;
}
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/DeductionGuideTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/DeductionGuideTests.java
new file mode 100644
index 00000000000..02705d96e5b
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/DeductionGuideTests.java
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * Copyright (c) 2018, Institute for Software 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Felix Morgner - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.core.parser.tests.ast2.cxx17;
+
+import static org.hamcrest.Matchers.arrayWithSize;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasToString;
+import static org.hamcrest.Matchers.is;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeductionGuide;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTestBase;
+import org.eclipse.cdt.core.parser.util.ArrayUtil;
+import org.hamcrest.MatcherAssert;
+
+public class DeductionGuideTests extends AST2CPPTestBase {
+
+ private static ICPPASTDeductionGuide firstGuide(IASTDeclaration[] array) {
+ return (ICPPASTDeductionGuide) ArrayUtil.filter(array, d -> d instanceof ICPPASTDeductionGuide)[0];
+ }
+
+ // template<typename> struct U;
+ // U() -> U<int>;
+ public void testDeductionGuideWithoutArguments() throws Exception {
+ IASTDeclaration[] declarations = parseAndCheckBindings().getDeclarations();
+
+ ICPPASTDeductionGuide guide = firstGuide(declarations);
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(0)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(false)));
+ }
+
+ // template<typename> struct U;
+ // U(int, float) -> U<int>;
+ public void testDeductionGuideWithArguments() throws Exception {
+ IASTDeclaration[] declarations = parseAndCheckBindings().getDeclarations();
+
+ ICPPASTDeductionGuide guide = firstGuide(declarations);
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(2)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(false)));
+ }
+
+ // template<typename> struct U;
+ // template<typename T>
+ // U(T) -> U<T>;
+ public void testDeductionGuideTemplate() throws Exception {
+ IASTDeclaration[] declarations = parseAndCheckBindings().getDeclarations();
+ ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) declarations[1];
+ ICPPASTDeductionGuide guide = (ICPPASTDeductionGuide) template.getDeclaration();
+
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(1)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(false)));
+ }
+
+ // template<typename> struct U;
+ // explicit U() -> U<int>;
+ public void testExplicitDeductionGuide() throws Exception {
+ IASTDeclaration[] declarations = parseAndCheckBindings().getDeclarations();
+
+ ICPPASTDeductionGuide guide = firstGuide(declarations);
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(0)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(true)));
+ }
+
+ // template<typename> struct U;
+ // template<typename T>
+ // explicit U(T) -> U<T>;
+ public void testExplicitDeductionGuideTemplate() throws Exception {
+ IASTDeclaration[] declarations = parseAndCheckBindings().getDeclarations();
+ ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) declarations[1];
+ ICPPASTDeductionGuide guide = (ICPPASTDeductionGuide) template.getDeclaration();
+
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(1)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(true)));
+ }
+
+ // struct S {
+ // template<typename> struct U;
+ // U() -> U<int>;
+ // };
+ public void testDeductionGuideWithoutArgumentsForNestedClassType() throws Exception {
+ IASTTranslationUnit tu = parseAndCheckBindings();
+ IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ ICPPASTCompositeTypeSpecifier struct = (ICPPASTCompositeTypeSpecifier) declaration.getDeclSpecifier();
+ IASTDeclaration[] members = struct.getMembers();
+
+ ICPPASTDeductionGuide guide = firstGuide(members);
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(0)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(false)));
+ }
+
+ // struct S {
+ // template<typename> struct U;
+ // U(char, bool) -> U<double>;
+ // };
+ public void testDeductionGuideWithArgumentsForNestedClassType() throws Exception {
+ IASTTranslationUnit tu = parseAndCheckBindings();
+ IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ ICPPASTCompositeTypeSpecifier struct = (ICPPASTCompositeTypeSpecifier) declaration.getDeclSpecifier();
+ IASTDeclaration[] members = struct.getMembers();
+
+ ICPPASTDeductionGuide guide = firstGuide(members);
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(2)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(false)));
+ }
+
+ // struct S {
+ // template<typename> struct U;
+ // template<typename T>
+ // U(T) -> U<T>;
+ // };
+ public void testDeductionGuideTemplateWithArgumentsForNestedClassType() throws Exception {
+ IASTTranslationUnit tu = parseAndCheckBindings();
+ IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ ICPPASTCompositeTypeSpecifier struct = (ICPPASTCompositeTypeSpecifier) declaration.getDeclSpecifier();
+ IASTDeclaration[] members = struct.getMembers();
+ ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) members[1];
+
+ ICPPASTDeductionGuide guide = (ICPPASTDeductionGuide) template.getDeclaration();
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(1)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(false)));
+ }
+
+ // struct S {
+ // template<typename> struct U;
+ // explicit U() -> U<int>;
+ // };
+ public void testExplicitDeductionGuideForNestedClassType() throws Exception {
+ IASTTranslationUnit tu = parseAndCheckBindings();
+ IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ ICPPASTCompositeTypeSpecifier struct = (ICPPASTCompositeTypeSpecifier) declaration.getDeclSpecifier();
+ IASTDeclaration[] members = struct.getMembers();
+
+ ICPPASTDeductionGuide guide = firstGuide(members);
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(0)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(true)));
+ }
+
+ // struct S {
+ // template<typename> struct U;
+ // template<typename T>
+ // explicit U(T) -> U<T>;
+ // };
+ public void testExplicitDeductionGuideTemplateForNestedClassType() throws Exception {
+ IASTTranslationUnit tu = parseAndCheckBindings();
+ IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ ICPPASTCompositeTypeSpecifier struct = (ICPPASTCompositeTypeSpecifier) declaration.getDeclSpecifier();
+ IASTDeclaration[] members = struct.getMembers();
+ ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) members[1];
+
+ ICPPASTDeductionGuide guide = (ICPPASTDeductionGuide) template.getDeclaration();
+ MatcherAssert.assertThat(guide.getParameters(), is(arrayWithSize(1)));
+ MatcherAssert.assertThat(guide.getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.getSimpleTemplateId().getTemplateName(), hasToString("U"));
+ MatcherAssert.assertThat(guide.isExplicit(), is(equalTo(true)));
+ }
+}

Back to the top