CLion 2024.1 Help

CLion Nova code style settings for C++

CLion Nova code style settings

On this page, you can configure various aspects of code style for C++. Code style preferences are grouped in tabs described below.

General

C++ Formatting Engine

Use these radio buttons to choose which formatting engine should be used when CLion Nova formats and reformats your C++ code.

  • ReSharper formatter — Use this option if you prefer the default set of ReSharper C++ formatting preferences or if you have configured formatting styles previously and saved it in layer-based settings (*.DotSettings).

    This option also enables code inspections that detect and highlight violations of formatting rules right in the editor.

    If you have some formatting styles configured in Clang-Format files, you can select Read code style from .clang-format files to apply most of these styles too. Note that settings from .clang-format files will override settings from *.DotSettings if there are any conflicts.

  • Clang-format — Use this option if you prefer the default LLVM-style formatting and want to format and reformats your code with the specified version of the clang-format code formatter.

Write current style to .clang-format

Click this button to export code styles from CLion Nova settings to a .clang-format file.

Tabs and Indents

This tab helps you specify how CLion Nova should format indents in your code when you type or when you reformat existing code.

Tabs and indents
Use spaces (recommended, looks aligned on any tab size)

When this option is selected, CLion Nova uses tabs for indents and spaces for alignment:

This is recommended option because code aligned with second and third options may lose alignment when viewed in an editor with a different tab size.

Only use tabs (inaccurate)

When this option is selected, CLion Nova uses tabs for both indents and alignment, which may not result in precise alignment:

Mix tabs and spaces for optimal fill

When this option is selected, CLion Nova uses tabs for both indents and alignment adds necessary spaces for precise alignment.

Naming

On this tab, you can configure symbol naming rules for C++.

Naming rules

Syntax Style

Preferences configurable on this tab help you enforce code syntax style. These preferences are taken into account when CLion Nova produces new code with code completion and code generation features, applies code templates and performs refactorings. They can also be applied to the existing code by using code cleanup with the corresponding settings.

The preferences with the Notify with selector have corresponding code inspections that notify you if this aspect of the syntax style in the inspected scope differs from the preferred style. Using the selectors, you can configure severity levels of the inspections.

Sort include directives

Select this option to highlight any #include directives that violate the sorting order.

Type of slashes to use in include directives

Use this checkbox to choose the preferred path separator for include directives: forward slash or backward slash.

Prefer to use forward declarations if possible

If this option is selected, auto-import puts the option to add a forward declaration before the option to insert an include directive.

Use paths relative to the source file

You can use this selector to configure when CLion Nova may use relative paths in generated include directives.

Use angle brackets instead of quotes

By default, generated include directives are added in quotes, if necessary, you can use this selector to specify cases where generated include directives are added in angle brackets.

Default pointer initializer

You can specify 0, nullptr or NULL as the preferred initializer for pointer initializers, for example: const char *foo = nullptr.

Use uniform initialization in member initializers

By default, CLion Nova uses C++03 style when generating initializers (for example when you generate constructors or apply a quick-fix that inserts initializer into an existing constructor). You can select this checkbox to enable uniform initialization in the above-mentioned cases.

Prefer uniform initialization in non-static data member initializers

This option lets you configure how CLion Nova generates non-static data member initializers (NSDMIs) when applying its features. For example, when you apply a quick-fix Alt+Enter on the uninitialized field in the following code

class test { int field; };

CLion Nova will generate a uniform initialization int field{0}; when the option is enabled, and int field = 0; if the option is disabled.

Sort member initializers by the order of initialization

This option lets you enforce the order of member initializers in constructor initializer lists. Class members are initialized in the order they are declared in their containing class, so to minimize confusion and errors the common practice is to keep member initializers in the same order.

'auto' usage in variable types

Preferences in this section let you configure the usage of auto separately for numeric and non-numeric types. The default for non-numeric types is When type is evident, which means that the auto specifier will only be introduced in the situations where the deduced type is evident from the initializer expression.

Position of cv-qualifiers

Preferences in this section let you configure whether the const keyword should be placed before or after the type it applies to, and which of the const and volatile qualifiers should go first.

Function declaration syntax

Use this option to configure whether to use trailing or regular return types in function declarations.

Prefer typedefs or type aliases

Use this option to specify the preferred way to define type synonyms: in the form of alias templates or type aliases. It also affects which syntax is used by the Introduce Typedef refactoring.

Nested namespaces

Use this option to enforce the C++17 syntax for nested namespaces, which allows you to declare multi-level namespaces in a more concise manner.

Overriding functions

Preferences in this section let you configure which specifiers should be required on overriding functions and destructors.

Braces

Preferences in this section let you define which braces can be omitted around single nested statements under the if statement and different kinds of loop statements. In addition to the straightforward Do not enforce > and Enforce always options, you can also opt to require braces only around statements that span several lines, or when the nested statement itself is multi-line.

Remove redundant

Use this option to configure whether CLion Nova should remove optional braces that do not comply with the chosen preference.

Braces Layout

Use this tab to adjust the way CLion Nova arranges braces when it generates new and reformats existing code; in particular, there are several ways to position braces after if or for operators.

For every item, there is a preview pane at the bottom part where you can observe changes after tweaking specific preferences.

Code style for braces

Blank Lines

This tab lets you configure whether CLion Nova should increase or decrease the number of blank lines around namespaces, members, regions and groups of import directives. You can adjust the values and check the preview pane at the bottom to see how your preferences affect the code.

Options in the Preserve Existing Formatting section are only applied when CLion Nova reformats existing code whereas the Blank Lines section contains options that also take effect when you type new code.

The options that you configure on this tab apply in the following cases:

  • When code is automatically formatted on editing or after pasting (you can toggle auto-formatting in Editor | General | Typing Assistance).

  • When code is generated with code completion and code generation features, when code templates are applied, and during refactorings.

  • When you reformat existing code.

Line Breaks and Wrapping

Use this tab to configure line breaks in certain positions of source code. Options in this tab are applied when CLion Nova reformats existing code or when you type new code. You can adjust the values and check the preview pane at the bottom to see how your preferences affect the code.

Code style options for line breaks

Spaces

Use this tab to configure how to insert or remove spaces in different code constructs. You can adjust the values and check the preview pane at the bottom to see how your preferences affect the code.

The options that you configure on this tab apply in the following cases:

  • When code is automatically formatted on editing or after pasting (you can toggle auto-formatting in Editor | General | Typing Assistance).

  • When code is generated with code completion and code generation features, when code templates are applied, and during refactorings.

  • When you reformat existing code.

Indentation and Alignment

You can use preferences on this tab to specify how CLion Nova indents and aligns your code in specific cases. In the Indentation group, you can define how tabs and indents (which you can configure in Code Editing | C++ | Formatting Style | Tabs and Indents) are applied in specific cases.

In the Align multiple constructs group, you can define how code constructs that span multiple lines are aligned (you can specify the rules for breaking long lines in Code Editing | C++ | Formatting Style | Line Breaks and Wrapping).

The options that you configure on this tab apply in the following cases:

  • When code is automatically formatted on editing or after pasting (you can toggle auto-formatting in Editor | General | Typing Assistance).

  • When code is generated with code completion and code generation features, when code templates are applied, and during refactorings.

  • When you reformat existing code.

Last modified: 16 April 2024