Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2016 IBM Corporation and others.
* Copyright (c) 2004, 2016, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -158,6 +158,7 @@ private static Map<String, String> getStdCpp20Map() {
Map<String, String> map = getStdMap();
map.put("__cpp_impl_three_way_comparison", "201907L");
map.put("__cpp_char8_t", "201811L");
map.put("__cpp_concepts", "201907L");
return map;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*******************************************************************************
* Copyright (c) 2025 Igor V. Kovalenko.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Igor V. Kovalenko - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2.cxx20;

import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTestBase;

/**
* AST tests for C++20 requires expressions.
*/
public class ConceptsTests extends AST2CPPTestBase {
// template<typename T>
// concept A = true;
//
// template<typename T>
// concept B = A<T>;
//
// template<typename T>
// concept C = requires {
// true;
// };
public void testConceptDefinitionExpressions() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP20);
}

// template<typename T>
// void x() requires true;
//
// template<typename T>
// void y() requires requires () {
// true;
// };
//
// template<typename T>
// void z() requires true && false;
public void testFunctionDeclarationTrailingRequiresClauseTrue() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP20);
}

// template<typename T>
// concept A = false;
// template<typename T>
// concept B = true;
// template<typename T>
// concept C = true;
//
// template<typename T>
// void x() requires true && false {}
//
// template<typename T>
// void x_c() requires C<T> {}
//
// template<typename T>
// void x_abc() requires A<T> || B<T> && C<T> {}
public void testFunctionDefinitionTrailingRequiresClause() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP20);
}

// template<typename T>
// concept A = false;
// template<typename T>
// concept B = true;
// template<typename T>
// concept C = true;
//
// template<typename T>
// requires A<T> || B<T> && C<T>
// void x() {}
public void testTemplateHeadRequiresClause() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP20);
}

// template<typename T>
// requires requires { true; }
// void x() {}
public void testTemplateHeadAdHocRequiresExpression() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP20);
}

// template<typename T>
// constexpr bool value = requires () { true; };
public void testInitializerRequiresExpression() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP20);
}

// template<typename T>
// constexpr bool x() {
// if constexpr(requires { true; }) {
// return true;
// } else {
// return false;
// }
// }
public void testConstexprIfRequiresExpression() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP20);
}

// template<typename T>
// concept A = false;
// template<typename T>
// concept B = true;
// template<typename T>
// concept C = true;
//
// template<A U>
// void f_a(U a_u);
// template<A U1, B U2, C U3>
// void f_abc(U1 a_u1, U2 b_u2, U3 c_u3);
public void testTemplateArgumentTypeConstraint() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP20);
}

// template<typename T>
// concept A = false;
// namespace Outer {
// template<typename T>
// concept B = true;
// namespace Inner {
// template<typename T>
// concept C = true;
// }
// }
//
// template<A U1, Outer::B U2, Outer::Inner::C U3>
// void f_abc(U1 a_u1, U2 b_u2, U3 c_u3);
public void testTemplateArgumentTypeConstraintFromNamespace() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP20);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2025 Igor V. Kovalenko.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Igor V. Kovalenko - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.index.tests;

import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConceptDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConcept;
import org.eclipse.cdt.core.testplugin.TestScannerProvider;

import junit.framework.TestSuite;

/**
* AST tests for C++20 concepts via PDOM.
*/
public abstract class IndexConceptTest extends IndexBindingResolutionTestBase {
public static class SingleProject extends IndexConceptTest {
public SingleProject() {
setStrategy(new SinglePDOMTestStrategy(true /* cpp */));
}

public static TestSuite suite() {
return suite(SingleProject.class);
}
}

public static class SingleProjectReindexed extends IndexConceptTest {
public SingleProjectReindexed() {
setStrategy(new SinglePDOMReindexedTestStrategy(true /* cpp */));
}

public static TestSuite suite() {
return suite(SingleProjectReindexed.class);
}
}

public static class ProjectWithDepProj extends IndexConceptTest {
public ProjectWithDepProj() {
setStrategy(new ReferencedProject(true /* cpp */));
}

public static TestSuite suite() {
return suite(ProjectWithDepProj.class);
}
}

private static void cxx20SetUp() {
TestScannerProvider.sDefinedSymbols.put("__cpp_concepts", "201907L");
}

@Override
public void setUp() throws Exception {
cxx20SetUp();
super.setUp();
}

public static void addTests(TestSuite suite) {
suite.addTest(SingleProject.suite());
suite.addTest(SingleProjectReindexed.suite());
suite.addTest(ProjectWithDepProj.suite());
}

// template<typename T>
// concept A = true;

// template<typename T>
// concept B = A<T>;
public void testConceptDefinitionFromHeader() throws Exception {
checkBindings();

ICPPConcept concept = getBindingFromASTName("B = A<T>", 1);
ICPPASTConceptDefinition decl = concept.getConceptDefinition();
}
}
2 changes: 1 addition & 1 deletion core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
Bundle-Version: 9.2.100.qualifier
Bundle-Version: 9.3.0.qualifier
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2015 QNX Software Systems and others.
* Copyright (c) 2006, 2015, 2025 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -32,6 +32,7 @@
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConcept;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.index.IIndexMacroContainer;
Expand Down Expand Up @@ -91,6 +92,10 @@ public static boolean bindingHasCElementType(IBinding binding, int[] kinds) {
if (binding instanceof IEnumerator)
return true;
break;
case ICElement.C_CONCEPT:
if (binding instanceof ICPPConcept)
return true;
break;
}
}
return false;
Expand Down Expand Up @@ -152,6 +157,9 @@ public static int getElementType(IBinding binding) {
if (binding instanceof IParameter) {
elementType = ICElement.C_VARIABLE_LOCAL;
}
if (binding instanceof ICPPConcept) {
elementType = ICElement.C_CONCEPT;
}
return elementType;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2014 QNX Software Systems and others.
* Copyright (c) 2000, 2014, 2025 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -249,6 +249,12 @@ public interface ICElement extends IAdaptable {
*/
static final int C_PRAGMA = 95;

/**
* a C++ concept.
* @since 9.3
*/
static final int C_CONCEPT = 96;

/**
* @deprecated use {@link IMethodDeclaration#isConstructor()}
* @noreference This field is not intended to be referenced by clients.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2025 Igor V. Kovalenko.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Igor V. Kovalenko - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.model;

/**
* Represents a C++ concept.
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*
* @since 9.3
*/
public interface IConcept extends IDeclaration, ITemplate {

}
Loading
Loading