ReSharper C++ 2019.3: C++20 Concepts, Type Hints, Sorting of #includes, and more
Please welcome ReSharper C++ 2019.3, our third and final update of this year!
ReSharper C++ 2019.3 introduces support for new C++20 features including Concepts, one of the most significant language changes in C++20. Type hints in the editor make your code easier to read. The new Sort #include directives context action and the accompanying inspection help you keep
#include directives in order, and there are also a number of new code checks thanks to bundled Clang-Tidy 9. For game developers working with Unreal Engine 4 projects, ReSharper C++ 2019.3 offers new live templates to generate UE4-specific code, in addition to support for UE4’s smart pointers.
Read on for more details about these features and other changes in the 2019.3 release:
- C++20 support
- Type hints
- Sorting of #include directives
- Code analysis and quick-fixes
- Unreal Engine 4 support
- Navigation improvements
- Additional project properties
- Other changes
If you’d like to try the new features completely free for 30 days, get the brand new build from our website.
C++20 is feature-complete and will officially be signed off next year to provide C++ developers with a range of long-awaited improvements. ReSharper C++ 2019.3 already supports many of these features, and C++20’s Concepts, one of the biggest language changes in the new standard, is now coming to ReSharper C++.
Concepts provide a way to express compile-time requirements on template arguments. They eliminate the need for a lot of ad-hoc template metaprogramming, and they enable the compiler to output better error messages. Visual Studio 2019 version 16.3 introduced support for Concepts in the compiler and the standard library, but as of yet the IDE itself does not feature support for Concepts.
In addition to updating our parser to understand the new syntax, all the major features of ReSharper C++ now support Concepts: Find Usages, Rename, code completion, and Quick Info. The code analysis engine takes constraints on function template arguments into account when performing overload resolution, and if a template constraint is not satisfied, the error is presented in an easy-to-read color-coded error message.
Please note that the work on supporting Concepts is still ongoing. Most notably, ReSharper C++ does not yet support the abbreviated function template syntax introduced by P1141.
ReSharper C++ 2019.3 also supports two new smaller C++20 features:
- Objects of aggregate classes in C++20 can be initialized from a parenthesized list of values, in addition to a brace-enclosed initializer list (see P0960). This change makes initialization more regular, which is useful for templates like
std::make_uniquethat need to create new objects and initialize them. This new initialization syntax is now supported by ReSharper C++, particularly in features like Parameter Info and member name hints.
- A small change in parsing rules was introduced by P0846, which allows unqualified calls to functions found later via ADL name lookup. As a result, in the following code the call to
std::getcan be unqualified in C++20:
We’ve also started a series of C++20 and ReSharper C++ blog posts, which you can use to learn about the new language features and their adoption in ReSharper C++.
Previous releases of ReSharper C++ already provided several different kinds of in-editor (“inlay”) hints that aimed to improve code readability: parameter and member name hints, as well as hints at the end of namespace declarations and conditional preprocessor directives. The 2019.3 release introduces type hints, which help you identify types that might not be obvious when you look at modern C++ code.
Type hints are available in several different contexts:
- For variables with automatically deduced type, which use the
decltype(auto)type specifiers. By default, the hint will be hidden if the deduced type is clear from the initializer expression, for example when the initializer is a constructor call, a constant, or an explicit cast.
- For loop variables in C++11’s range-based for loops.
- In C++17’s structured binding declarations, where type hints are especially useful since the type of a structured binding cannot be explicitly specified.
- After function calls. With the default settings, this kind of type hint is shown only after multiline chained member functions calls. While not very widespread in C++, chained function calls are sometimes used when working with classes that follow the Builder design pattern.
- For automatically deduced return types of functions and lambdas.
If you want to quickly disable type hints, right-click on a hint to open the context menu. From the same menu, you can go to the options page or navigate to the type declaration (alternatively, click on the hint while holding down Ctrl to perform the navigation).
Type hints can be configured on the Environment | Editor | Inlay Hints options page. The settings on this page affect hints in both C++ and C# where applicable.
In 2019.3, type hints are disabled by default in dependent code. Though it is possible to re-enable them, because of performance concerns, we do not recommend doing so. We plan to resolve these issues in a future release.
We hope type hints make code easier to read for you. If you have any feedback or suggestions on how we can improve this new feature, please do not hesitate to contact us.
Sorting of #include directives
ReSharper C++ 2019.3 finally resolves one of the most-voted-for feature requests in our issue tracker: sorting of
#include directives (RSCPP-10537). Our implementation of this feature is influenced by and compatible with the
#include ordering options of Clang-Format.
Let’s say that several consecutive
#include directives not separated by a blank line or any other code form a group of directives. According to this definition, there are three groups in the following code snippet:
Now, when the caret is on an
#include directive, a new context action Sort #include directives will be available. You can choose one of the three ways the action should operate from the action submenu. Sort and regroup #include directives will merge all
#include groups into one, and then sort it and split into new groups according to the configured settings.
Sort each #include group separately will not change the existing grouping, but it will sort
#include directives inside each group independently of other groups.
Finally, Sort only current #include group will simply sort just the group that the caret is on.
You can configure the rules used for sorting
#include directives on the ReSharper | Options | Code Editing | C++ | Code Style page.
#include directives are sorted according to the rules listed in the Sort order grid, where rows represent either a special kind of header (a precompiled header or the main header for the current file) or all
#include directives with names that match a regular expression pattern. You can also add blank lines that are used during regrouping.
There are two more settings available on the options page. Preserve existing #include groups during a sort determines whether the top level Sort #include directives action should regroup directives or sort each group separately. When Enable inspection ‘Order of #include directives does not match code style settings’ is enabled, ReSharper C++ will highlight any
#include directives that violate the sorting order.
We’re definitely not done with this feature yet, as we are planning to address the following issues in the 2019.3.X bugfix updates or in the next release:
- Add sorting of
#includedirectives to Code Cleanup (RSCPP-28428).
- Update auto-import to insert the new
#includedirective according to the sorting rules (RSCPP-18736).
- When a
.clang-formatfile is present, import the
#includesorting settings from it (RSCPP-28448).
In this release we’ve upgraded the built-in Clang-Tidy to Clang 9 to give you lots of new code checks and accompanying fixes. We’ve also updated the bundled binary so that it no longer occasionally prevents modifications to the source files.
Clang-Tidy runtime settings are now more flexible:
- The Clang-Tidy executable to use setting now has three options to choose from. In addition to the bundled binary and a custom binary, you can now select the one from %PATH% (ReSharper C++ will search in folders listed in the %PATH% environment variable and let you know if it finds anything). This might be useful if you want to use Clang-Tidy from the latest LLVM toolchain installed on your machine.
- You can now point ReSharper C++ to a specific Clang-Tidy configuration file instead of a YAML/JSON format string as before. The contents of this file will automatically be converted into a command-line argument and passed to Clang-Tidy.
Warnings from the Clang compiler can now be disabled from the inspection menu similar to Clang-Tidy checks.
On the performance side, ReSharper C++ now starts Clang-Tidy earlier in the code analysis process, as it doesn’t wait for other code analyses to finish.
Code analysis and quick-fixes
A new code inspection warns you about local variables that are used inside a lambda body but that are not captured by the lambda. If you want to capture a variable, a family of quick-fixes will assist you with updating the capture list. ReSharper C++ will offer either to capture the variable or
this by value, by reference, or to implicitly capture all the used automatic variables.
If you want to turn off a particular inspection in the entire file or even to suppress all the inspections, you can now quickly do so with the new Disable in file with comment and Disable all inspections in file with comment actions in the inspection menu.
Performance improvements were a major focus in the ReSharper C++ updates this year, and 2019.3 brings even more performance boosts.
First, we’re continuing our work on the initial indexing time, which we started in the 2019.1 and 2019.2 releases. According to our measurements, ReSharper C++ 2019.3 indexes large solutions such as LLVM 5% faster on average than 2019.2 did.
Second, Find Usages was sped up. By taking the inclusion graph into account, Find Usages is now able to filter out even more source files that cannot possibly contain any usages. Thanks to this change, the Rename and Change Signature refactorings will also run faster.
Finally, we’ve optimized code analysis after local modifications. After you make a change inside the body of a function, ReSharper C++ will rerun code inspections only on the function itself. This should significantly reduce the total code analysis time for large source files.
Unreal Engine 4 support
When ReSharper C++ detects you are developing an Unreal Engine project, it adjusts its behavior to be more UE4-specific. ReSharper C++ 2019.3 brings handy new features for UE4 developers.
Live templates with the corresponding names are now available to help you quickly generate
UENUMCLASS. These templates can be used in header files only when the corresponding
.generated.h header is included.
ReSharper C++ now includes built-in support for Unreal Engine’s smart pointers:
TUniquePtr. This means features like Parameter Info, code analysis, and postfix code completion handle Unreal smart pointers in the same way they do the standard
std::unique_ptr smart pointers.
Speaking of postfix code completion, the new postfix template for classes derived from
UCLASS now expands to a proper factory function call that registers the constructed object in the garbage collector. Objects of classes derived from
UActorComponent are created using the
CreateDefaultSubobject function, objects of classes derived from
AActor using the
SpawnActor function, and all the other
UCLASS derivatives are constructed with
We’ve also fixed several performance issues in UE4 projects. In particular, the annoying hang after using Refresh Visual Studio Project in the UE4 editor should be gone now.
When an aggregate object is initialized using a brace-enclosed initializer list, the name of the aggregate class can sometimes be omitted. You can now use Go to Declaration on the opening brace to navigate to the aggregate class.
Go to file member (Alt+\) was improved in more ways than one:
- The dialog is now shown instantly without waiting for the file to be parsed. This fixes the problem in earlier releases where some of the input might get lost while the file is being parsed.
- A single member function will not be shown twice even if both its declaration and definition are in the same file.
- A bug was fixed that caused class members from the header file not to be shown when the Include base members checkbox was selected.
Additional project properties
To provide code assistance, ReSharper C++ needs to learn some compilation properties, such as include paths, preprocessor definitions, and so on. Usually these compilation properties are read from Visual Studio projects, but for custom compiler toolchains (which are often used in embedded projects), it might be necessary to provide an alternative way of specifying compilation properties.
In ReSharper C++ 2019.3 this is now possible using the Properties tool window. Select a project in Solution Explorer, and you’ll be able to set the language standard to use and add additional include directories or preprocessor definitions in the tool window. Remember that these properties get used only by ReSharper C++ and do not affect compilation in any way.
These project settings are automatically saved in a
.vcxproj.DotSettings file next to the project file, so they can be shared between team members and will be preserved even if the project file is regenerated.
If you use .clang-format files to maintain your code style settings, it is now possible to export the formatting settings to a .clang-format file. To do this, click the Write current style to .clang-format button on the ReSharper | Options | Code Editing | General Formatter Style options page.
You can now use the new advanced “Group by” functionality in the Unit Test Explorer and Unit Test Session tool windows to create a custom grouping. With the added Duration element, you can now group unit tests based on the time it takes them to execute.
We’ve also renamed several live templates to match the corresponding language keywords. For example, to generate a class, type
cls before); for structures, use
struct instead of
str; and use similar logic for unions, enums, and namespaces. If you want to complete a keyword instead of expanding a live template, press Space instead of Enter or Tab.
That covers the biggest changes in ReSharper C++ 2019.3. The full list of all 170+ issues fixed in this release can be found in our issue tracker. We also encourage you to check out the What’s New on the ReSharper Ultimate 2019.3 page.
Subscribe to Blog updates
Thanks, we've got you!
ReSharper C++ 2023.2: Safe Delete Refactoring, AI Assistant, New C++23 and C++20 Features
New release brings the Safe Delete refactoring, support for several new C++20 and C++23 features, ReSharper’s AI Assistant, and more.
ReSharper C++ 2023.1: Call Tracking, Macro Expansion Preview, and Support for C++23 Features
ReSharper C++ 2023.1 brings updates for C++20 and C++23 features, and also introduces Call tracking for incoming calls and macro substitution previews in tooltips and Quick Documentation popups.
ReSharper C++ 2022.3: C++20 Modules and Clang-Format Integration
ReSharper C++ 2022.3 introduces experimental support for C++20 modules and provides seamless integration with clang-format.