News Releases

ReSharper C++ 2021.2: Type Conversion Hints, Immutability Inspections, Inline Function

Read this post in other languages:

ReSharper C++ 2021.2 is now available for download! It brings new inlay hints to help you spot implicit type conversions, the Inline Function refactoring, and updates to Unreal Engine support. New modernizing inspections assist you with updating your code to modern C++, and improved immutability analyses keep your code more readable and correct.

ReSharper C++ 2021.2

Update to this version, or start a free 30-day trial today! The brand new build is available on our website, and all our tools for Visual Studio can be downloaded via the Toolbox App.

DOWNLOAD RESHARPER C++ 2021.2

Read on for details about all the new features and improvements in 2021.2:

Type conversion hints

In ReSharper C++ 2021.2, we’ve introduced new inlay hints that show implicit type conversions. Implicit conversions in C++ are automatically performed by the language whenever a value of one type needs to be converted to a value of another type. Even though implicit conversions can make your code more concise, they might also have a performance cost or lead to a loss of precision when converting between numeric types.

ReSharper C++ displays hints for different kinds of class type conversions, including object copying, object initialization using converting constructors, aggregate initialization, and calls to conversion operators.

Type conversion hints for aggregate initialization

Another set of hints covers standard language conversions to or from built-in types, such as conversions between numeric types that might lose precision or change the signedness of the type.

Integral type conversion hint

Hints for standard conversions are disabled by default, but you can enable them on the Environment | Inlay Hints | C++ | Type Conversion Hints page of ReSharper settings.

You can also configure an exclusion list to hide conversion hints for a specific class, and select the preferred display mode to show hints as a special icon or code. For your convenience, these settings can be configured from the Alt+Enter or right-click context menu.

An exclusion list for type conversion hints

Check out this blog post for more details about type conversion hints.

Inline Function

The new Inline Function refactoring lets you quickly replace a function call with the body of the function. To invoke it, place the caret on a function call and select Inline Function from the Refactor This menu, or choose ReSharper | Refactor | Inline from the main menu.

Inline Function refactoring

ReSharper C++ will perform the necessary transformations, handle all the name conflicts, and reformat the resulting code. Or, if inlining the method doesn’t seem like a good idea, it will show you a short pop-up message explaining why.

Immutability inspections

In ReSharper C++ 2021.2, we’ve continued our work on immutability-related analyses and introduced two new inspections to cover the remaining rules from the Constants and immutability section of the C++ Core Guidelines.

  • The first new inspection extends the immutability analysis for function parameters of reference and pointer types. ReSharper C++ will notify you if you can pass a pointer or a reference to const, which guarantees that the function will not modify the corresponding function argument.
    Parameter can be made reference to const
  • The second inspection suggests marking variables that can be evaluated at compile-time with constexpr, which can lead to faster performance and better compile-time checking.
    Use constexpr for values that can be computed at compile time

We’ve also reworked the existing inspections for local variables and parameters and improved control-flow analysis for the standard library, so now you’ll get const suggestions in more cases.
Use const to define objects with values that do not change after construction

Learn more about these and other immutability inspections included in ReSharper C++ in this blog post.

Code generation

How would you prefer functions to be generated by default? To make code generation even more convenient, we’ve added several settings to let you configure generated function definitions. All of the new settings are available on the Code Editing | C++ | Code Generation page of ReSharper settings.

Code Editing | C++ | Code Generation

By default, ReSharper C++ generates functions with empty bodies, but with the Default function body setting, you can now specify whether the generated functions should throw an std::logic_error, return a default value, or include uncompilable code.
The generated function throws std::logic_error

When generating the body of an overriding function, ReSharper C++ will now automatically call the base function if the corresponding setting is checked.
Call the overriden function

Finally, ReSharper C++ can create idiomatic bodies of operator functions that are usually implemented in terms of the associated operator.
Generate default operator implementation

The new code generation settings affect all ReSharper features that can create a function body, including Generate workflows and the related context actions.

Unreal Engine

ReSharper C++ 2021.2 comes with full support for Unreal Engine 5! Now you can check out its Early Preview and enjoy all the same UE-specific features as for existing Unreal Engine 4 projects.

We’ve improved code completion and code analysis to help you work with modules and plugins:

  • In the .Build.cs and .Target.cs files of an Unreal Engine project, ReSharper C++’s code completion now suggests the list of available modules and plugins.
    Code completion for module and plugin names
  • The new inspection for missing dependencies will highlight usages from unreferenced modules and plugins. Use the accompanying quick-fixes to include the required header or add new modules and plugins to the .uproject or .uplugin file.
    Add missing plugin dependency

Thanks to updated code generation for function definitions, ReSharper C++ will now call the overridden function from the generated body of an overriding function using the idiomatic Super type alias.
The Unreal Engine Super typedef in the generated body

We’ve also improved the performance and memory usage of a cold startup. Now ReSharper C++ indexes the Unreal Engine code base up to 10% faster.

Modernizing inspections

ReSharper C++ 2021.2 adds more inspections to help you modernize your code:

  • Structured binding can be used instead of tie(..): since C++17, you no longer need to use std::tie() or boost::tie() for unpacking a tuple or a pair – structured binding declarations help you simplify your code.
    Structured binding can be used instead of tie(..)
  • Type trait can be simplified using a template alias or a variable template: C++14 alias templates let you shorten C++11 type trait expressions.
    Type trait can be simplified using a template alias or a variable template
  • std::size can be used: this inspection suggests using std::size as a type-safe alternative to the error-prone C idiom for array size calculation.
    std::size can be used
  • Zero initialization can be used instead of memset: zero-initialization leads to more concise code and prevents various memset-related errors.
    Zero initialization can be used instead of memset

Coding assistance

Do you find yourself puzzling over strings that contain a lot of special characters? You can now use new context actions to convert any string into a more readable C++11 raw string literal, and vice versa.

Convert to raw string literal

If you want to quickly consult cppreference.com about the details of a standard library class or function, you can now click Read more in the Quick Documentation pop-up (Ctrl+Shift+F1) to open the corresponding page in your browser.

Embedded links to cppreference.com

With smart Backspace, you can now place the caret at the proper indent position instead of moving it back one position at a time. To configure the preferred unindent on Backspace, go to the Environment | Editor | Behavior page of ReSharper settings.
Unindent on Backspace

Other changes

A new inspection warns you when you compare an unsigned expression with 0, which may cause an infinite loop or unreachable code.

Comparison is always true

The bundled Clang-Tidy has been updated to Clang 12, adding new checks from the latest LLVM release. We’ve also improved its performance in complex files, particularly in C++20 projects.

Clang-Tidy 12

ReSharper C++ now supports two new compiler switches from Visual Studio 16.10:

  • The /std:c++20 language standard switch.
  • The /await:strict switch, if you want to use C++20-style coroutines but are targeting C++14 or C++17.

That’s it! The full list of new features and bug fixes includes more than 180 issues and is available in our issue tracker. Also, more changes are coming from the ReSharper platform; for example, the InspectCode command line tool now restores NuGet packages and builds a solution before starting its analysis. Take a look at What’s New in ReSharper, as well.

What’s your favorite improvement in this release of ReSharper C++ 2021.2? Give the new release a try and share any feedback – we love hearing from you!

DOWNLOAD RESHARPER C++ 2021.2

Your ReSharper C++ team
JetBrains
The Drive to Develop

image description