# Support for C++20 Concepts

[Concepts](https://en.cppreference.com/w/cpp/language/constraints) are one of the major language features of the [C++20](https://en.cppreference.com/w/cpp/20) standard. They provide a way to put compile-time constraints on template arguments, helping you ensure the templates meet your expectations.

> **Tip:**
> For more information about Concepts, watch this talk from CppCon 2019 by [Saar Raz](https://github.com/saarraz), the author of concepts implementation in Clang: [C++20 Concepts: A Day in the Life](https://youtu.be/qawSiMIXtE4)

## Configure Concepts support

Procedure: 1. Set up the compiler

1. The compiler you are using should support the C++20 Concepts feature.

Clang:

* Use Clang10 or later. You can check the status of a particular C++20 feature in [C++ Support in Clang](https://clang.llvm.org/cxx_status.html).

GCC:

Use [GCC 10](https://gcc.gnu.org/gcc-10/) or later. The implementation of Concepts in GCC10 fully [conforms to C++20](https://gcc.gnu.org/projects/cxx-status.html).

MSVC:

MSVC supports Concepts since Visual Studio version 16.3. Note that terse syntax (`void fn(MyConcept auto mc)`) is not supported yet.

Adding `#define __cpp_lib_concepts` might be required for correct resolve (see the comments to the [Microsoft announcement](https://devblogs.microsoft.com/cppblog/c20-concepts-are-here-in-visual-studio-2019-version-16-3/)).

Procedure: 2. Set the project standard to C++20

CMake project

* When [creating a new project](creating-new-project-from-scratch.html#create-prj), select C++20 in the Language standard field of the New Project wizard.

* For an existing project, set the `CMAKE_CXX_STANDARD` variable at the beginning of `CMakeLists.txt`:

```CMAKE
set(CMAKE_CXX_STANDARD 20)
```

Makefile project

Set the `CXXFLAGS` variable in the Makefile:

```MAKE
CXXFLAGS += -std=c++20
```

Meson project

Set the `cpp_std` compiler option:

```CONSOLE
cpp_std=c++20
```

> **Tip:**
> Concepts support in CLion works the same regardless of the project format: [CMake](quick-cmake-tutorial.html), [Makefiles](makefiles-support.html), [Meson](meson.html), or [compilation database](compilation-database.html). Make sure to set the language standard to C++20 and use an appropriate compiler.

Procedure: 3. Make sure Clangd completion is enabled

By default, CLion's code completion is performed by the [Clangd-based engine](settings-languages-cpp-clangd.html). When working with Concepts, use the default option Only Clangd completion or switch to Clangd completion merged with builtin.

1. Go to `Settings | Languages & Frameworks | C/C++ | Clangd`.

2. In the Code completion section, set the Use code completion via clangd checkbox:

![Clangd completion options](https://resources.jetbrains.com/help/img/idea/2026.2/cl_clangd_completion.png)

## Code insight for Concepts

### Parsing and highlighting

CLion parses and highlights all the standard syntax forms for `concept` and `requires`:

![Supported syntax forms for Concepts](https://resources.jetbrains.com/help/img/idea/2026.2/cl_concepts_syntax_forms.png)

You can tune the highlighting settings for Concepts in `Settings | Editor | Color Scheme | C/C++ | Templates | Concept`. By default, the scheme is inherited from C/C++ Class/struct/enum/union.

![Syntax highlighting settings for Concepts](https://resources.jetbrains.com/help/img/idea/2026.2/cl_concepts_custom_highlighting.png)

### Code analysis

A set of [inspections](code-inspection.html) with quick-fixed is available for your code using Concepts.

Among the inspections, some checks come from the compiler:

![An example of compiler check for Concepts](https://resources.jetbrains.com/help/img/idea/2026.2/cl_concepts_compiler_check.png)

The Unconstrained variable type inspection suggests constraining local variables declared as `auto` if the result of a constrained expression or function call is assigned to them. This inspection is disabled by default on Windows.

![Unconstrained variable type](https://resources.jetbrains.com/help/img/idea/2026.2/cl_concepts_constrain_inspection.png)

### Code completion, navigation, and refactoring

Code completion for Concepts is available in the following cases:

* Completion for template type parameters that are constrained: ![Completion for constrained types](https://resources.jetbrains.com/help/img/idea/2026.2/cl_concepts_completion_constrained_types.png)

* Completion for types constrained by `std::is_base_of<MyBase, T>` and `std::is_same<Other, T>`. The list of suggestions on `T` in `std::is_base_of<MyBase, T>` and `std::is_same<Other, T>` includes the options from `MyBase` and `Other`, respectively: ![Completion for types constrained by std::is_base_of and std::is_same](https://resources.jetbrains.com/help/img/idea/2026.2/cl_concepts_completion_issame_isbase.png) Note that completion for this case works only if `MyBase` and `Other` are concrete types (not template types).

[Rename](rename-refactorings.html) refactoring and navigation actions like [Go to Definition](navigating-through-the-source-code.html#go_to_implementation) and [Find Usages](find-highlight-usages.html) are also supported for code with Concepts.

## See also

### External Links

[isocpp.org: articles tagged with 'Concepts'](https://isocpp.org/blog/tag/concepts) [CLion blog: Support for C++20's Concepts in CLion](https://blog.jetbrains.com/clion/2019/11/cpp20-concepts-in-clion/) [CppCon 2019: Saar Raz 'C++20 Concepts: A Day in the Life' (video)](https://youtu.be/qawSiMIXtE4)

### Procedures

[Clangd settings](settings-languages-cpp-clangd.html) [C++ keywords completion](c-keywords-completion.html)

