Early Access Program News

CLion starts 2021.2 EAP: CMake Presets, New Project Templates, Lifetimes Analysis, and Cling support

The CLion 2021.2 EAP program has now begun! The first EAP build is ready for you to try out. If you want to know what we are working on in particular during this release cycle, please read this roadmap blog post.

CLion EAP 2021.2

EAP builds are free to use, but might be unstable and of lower quality. The main goal of these builds is to let our users evaluate the features which will be added to the next release and share their feedback at early stages. These builds also can be used to test the changes in rare and very specific environments, which are hard to cover from our side.

Build 212.3116.34 is available from our website via the Toolbox App, or as a snap package (if you are using Ubuntu). Note that if you are on macOS, there is a separate build for Apple Silicon (M1 chip).

DOWNLOAD CLION 2021.2 EAP

Check out the main highlights and read the post for more details:

CMake

CMake 3.20

CMake 3.20 is now supported and bundled in CLion. This version includes CMake Presets, major updates to CMake File API, support for C++23 compiler modes, and many updates for CUDA developers.

CMake Presets

CMake Presets are a new way to configure CMake options and share them with others. It’s all thanks to two files:

  • CMakePresets.json is meant to save project-wide builds, and may be checked into VCS.
  • CMakeUserPresets.json is meant for developers to save their own local builds, and should not be checked into VCS.

CLion, on the other hand, operates with CMake Profiles – entities which are specific to CLion but have many settings in common with the CMake Presets and are also shareable via VCS. The major difference is that they reference CLion toolchains, which shouldn’t be mixed with the CMake toolchains. They serve different purposes and CMake toolchains can’t cover CLion use cases. The CLion toolchain serves other project models and contains information that is not present and not needed in the CMake toolchain, like the debugger and environment settings (remote host, WSL, etc.).

Now that we’ve explained the difference, we’d like to announce that CLion now supports importing information from CMake Presets. This is just the first step toward CMake Presets support in CLion and we are eager to hear your feedback on how we are doing.

The Load CMake Presets action (use Find Action via Ctrl+Shift+A/⇧⌘A to find it by name) searches through the existing Build Presets and shows them in the popup:
Load CMake Preset

When selected, CMake Preset is imported into CLion CMake Profiles read-only mode. You can review the list of profiles in Settings/Preferences | Build, Execution, Deployment | CMake.
Preset is loaded

Known limitations and further plans:

  • Imported presets are read-only. However, you can open the corresponding JSON files, edit them in CLion, save the file (currently, autosave is not supported – CPP-25076) and reload the preset in CLion.
  • CLion at present supports only version 2 presets and only buildPresets.
  • After importing, CMake Preset in CLion gets a link to the CLion toolchain. For now, it’s the Default toolchain, but later we’ll provide a way to configure it.
  • Other issues logged as subtasks to this one.
  • The general task for supporting CMake Presets in CLion is much wider (CPP-22906) and will likely include a way to update presets from CLion UI.

CMake Project Templates

In addition to the CMakeList.txt file template for a new file, CLion now also provides editable templates for new CMake projects. You can find them in Settings/Preferences | Editor | File and Code Templates | Other:
CMake templates

C and C++ libraries and executables, CUDA libraries and executables, and Qt projects are available there. These templates are used when you create a new project via the File | New Project wizard.

CMake targets as Before Launch tasks

In the Before Launch section of the Run/Debug configuration, users can specify the tasks to be performed before starting the selected target. By default, there is a Build step there. You can now add a CMake Target task in this phase to execute the CMake target:
Before Launch

Both built-in (like for example, all, clean, install) and user-specified (created via add_executable or add_custom_target) targets will be suggested:
Clean Before Launch
Learn more

Lifetimes analysis

According to the C++ Foundation Developer Survey, memory safety issues like use-after-free/delete are among the top points of frustration for C++ developers. The Lifetime Safety proposal is trying to address these issues in the C++ language. The idea is to diagnose common cases of dangling pointers and references (use-after-free, use-after-move) at compile time, by using local analysis. Local analysis uses the concepts of Owners, Shared Owners, and Pointers. The GSL library brings annotations to mark the code and help local analysis.

The proposal is still under discussion, but there is an experimental Clang branch supporting some ideas from the proposal, and Today Lifetime analysis comes to CLion!

For example, here CLion warns you about the string view referencing an invalid object after the temporary string is destroyed: Lifetime sample

Various cases of local variables pointing to memory which is out of scope are also caught by CLion:
Out-of-scope sample

GSL annotations are also supported in the analysis:
GSL Annotate Lifetimes

The analysis runs in the scope of the function body. While it doesn’t catch all the issues, it can already help significantly with one of the most troubling C++ issues.

Cling Support

You might not expect it, but there is an interactive C++ interpreter, Cling (check out its GitHub page), built on top of Clang and LLVM. It’s really useful for prototyping and learning C++. You can find a short video here which explains the basics of working with Cling.

With this EAP, Cling is now supported in CLion! To start with Cling in CLion, download the cling executable for your platform or install it via your OS-specific dependency manager (like brew on macOS), and configure a path to it in Settings/Preferences | Languages & Frameworks | C/C++ | Cling. It will be autodetected by CLion if Cling is in PATH.

You are ready to go! In the Tools menu, you will find the related Cling actions, or you can call them from Find Action.
Cling Tools
For lines of code, an intention is available that sends the current line to the Cling session:
Cling intention
You can select several lines, press Alt+Enter, and send the whole selection to Cling. You can also just load a whole file to Cling, or simply type code directly in the Cling terminal:
Cling in action

There are a few known limitations worth mentioning:

  • Users can’t add extra arguments to the Cling executable starting from within CLion for now, so you can’t really change the C++ language standard or other options.
  • Project flags are not passed to the Cling session (CPP-25256). This might cause an issue with some included paths not known to Cling.
  • The Cling session is started within the project directory or within the home directory (if no project is currently open). The relative paths might not be handled correctly when sending a current line to Cling from a file that is not in the project root..

WSL enhancements

You no longer need an SSH server inside a WSL distribution to work with WSL in CLion. WSL processes are now started using a dedicated WSL API, making WSL configuration in CLion much easier.

CLion now supports WSL installed not only from the Microsoft Store, but also from custom distributions. The IDE shows all imported WSL distributions in the drop-down list on the dedicated Toolchains settings page (the list is the same as the one returned by the wsl -l -v command).

Text search in Local History

If your project is not under version control, you are still safe from any bad changes (like deleted files). With Local History you can roll back to any past state of a file, even if no version control is enabled for your project. It allows text search through the file revisions so that you can locate the point you want to rollback to more easily.

And more

  • This build addresses several IDE freezes, specifically related to copy-pasting activities.
  • A few new MISRA checks are added.
  • Starting from this EAP, it is possible to navigate back and forth between open sections in Preferences/Settings. To do so, use the arrows in the right-hand corner of the window.
  • The difference between the initial and changed files is now always displayed in the editor, regardless of how you invoke the Show Diff action. If you find it more convenient to track changes in a separate window, you can drag the desired file from the editor. If you do, the IDE will remember this and will open future diffs in a separate window.
  • It’s now easier to code with the enabled screen reader mode on macOS – a list of available suggestions for code completion is now read out loud.

The full release notes are available here.

DOWNLOAD CLION 2021.2 EAP

Your CLion team
JetBrains
The Drive to Develop

image description