CLion 2023.3 Help

Support for C++20 Modules

Modules were introduced in the C++20 standard. They work as alternative to some use cases of header files and help share declarations and definitions across translation units.

CLion collects information from .ixx, .cppm, and .mxx files, parses export module {name} statements and creates mappings between {name} and module filenames. Then, the mappings are passed to the Clangd engine and used to provide coding assistance and highlighting.

If you update the module’s code or rename the module, CLion will automatically parse the changes. The information collected from modules is preserved between the IDE restarts.

CLion's support for modules has been tested in the following environments:

  • CMake, Ninja generator, Visual Studio C++ toolchain.

  • CMake, Visual Studio generator, Visual Studio C++ toolchain.

  • CMake, Clang toolchain with compiler flags.

Code insight for Modules

  • CLion highlights module keywords (import, export, and module):

    Modules keywords highlighting
  • Completion works for symbols from modules:

    Completion for symbols from modules
  • You can navigate between declarations and definitions of symbols from modules using Ctrl+B:

    Navigation for modules
  • Find Usages and refactorings are available inside modules.

    There are also early versions of the Rename, Change Signature, and Extract refactorings that work across module boundaries (for now, they only work for files opened in CLion).

Adding modules

In CLion, you can add new modules to your project automatically.

  1. In the project tree, right-click the folder where you want to add a module and select New | C++ Module Interface Unit:

    New module menu
  2. Specify the module name, its type (extension), and whether you want CLion to add the newly created module to an existing CMake target:

    New module dialog
  3. A new module will be created in your project tree and added to the CMakeLists.txt script if you chose that option:

    New module created

    You can edit the template that CLion uses when creating module files in Settings | Editor | File and Code Templates:

    C++ Module file template settings
Last modified: 15 March 2024