News Releases

What’s New in ReSharper C++ 2018.2

Please welcome ReSharper C++ 2018.2!

While ReSharper C++ 2018.1 introduced two major new features, debug step filters and includes analyzer, ReSharper C++ 2018.2 is focused on improving its understanding of the C++ language. The biggest highlight is its long-awaited support for C++/CLI. In addition, many important features from C++17 and even the upcoming C++20 have been implemented. Code analysis is enhanced with spell-checking inspections powered by the newly bundled ReSpeller plugin, as well as formatting inspections to help you maintain a consistent code style.

800x400_blog

Download ReSharper C++ 2018.2

Initial C++/CLI support

C++/CLI is a set of C++ language extensions by Microsoft designed for easy interoperability between managed and native code. With extensive support for both managed languages and C++, it is only natural for ReSharper to offer help with writing code in C++/CLI too.

Generics, value and ref classes, handles, tracking references, and interfaces are just some of the new language constructs in C++/CLI introduced to support managed semantics. With so many syntactic additions and peculiar changes to the C++ language, handling C++/CLI is no easy task. But now the wait is over — ReSharper C++ 2018.2 makes its C++/CLI support public, with many major features (including code inspections, typing assistance, formatting, and code completion) updated to support this language dialect.
C++/CLI navigation

Please remember that this section is named “Initial support” for a reason, and our work on C++/CLI is by no means done. To name just a few limitations: #using directives are not supported, auto-import does not work for CLR classes, and class hierarchy navigation features have limited functionality. While Find Usages and Go To Declaration will work between C++/CLI and C#, refactorings like Rename cannot cross the language barrier yet. The entire list of active issues is available in YouTrack.

C++/CLI is a unique beast. It is used mostly in enterprise projects and in-house codebases, so the number of open source projects that rely on it is very small. This means that we do not have a significant number of available projects to test on. As we move to expand our coverage, we would love to hear your feedback on what is missing and what you feel we should concentrate on.

Note that C++/CLI support requires a ReSharper Ultimate subscription and the ReSharper product to be enabled. If you find that you want to fall back to bare Visual Studio when editing C++/CLI sources, you can disable C++/CLI support in ReSharper C++ completely using the Enable C++/CLI support option on the Code Editing | C++ | Inspections option page. To learn more, see C++/CLI support comes to ReSharper C++.

C++17 features

Another area that we have been putting a lot of effort into is our ongoing work on C++17 support. ReSharper C++ 2018.2 adds understanding of the following new features:

  • Class template argument deduction (P0091) lets you omit explicit class template arguments if they can be automatically deduced from constructor arguments.
    Class template argument deduction
    You can also specify how to deduce class template arguments from constructor arguments yourself via user-defined deduction guides. As an example, by using a custom deduction guide, you can enable template argument deduction for a constructor of a container class which accepts a pair of iterators:
    Deduction guides
    The standard library uses a similar approach with its containers.
  • Fold expressions (N4191) are a new kind of expressions inside variadic templates. The aim of fold expressions is to provide a simple way to apply binary operators to parameter packs. Here is how you can calculate a bitmask in C++17 using a unary right fold expression:
    Fold expression
  • Auto non-type template parameters (P0127) let you indicate that the type of a non-type template parameter should be deduced at the point of instantiation. One interesting application of this feature is variadic templates which accept a list of heterogeneous constant values as template arguments:
    Auto template parameters
  • With pack expansions in using declarations (P0195), it is now possible to introduce a name from a pack of classes inside a variadic template. The following snippet, which uses both this feature and class template argument deduction, shows how easy it is in C++17 to overload over a set of lambda objects:
    Pack expansions in using declarations
  • Using declarations with multiple declarators is a straightforward change to the syntax of using declarations, which lets you introduce several names in the same declaration.
    Using declaration with multiple declarators
  • Some say that guaranteed copy elision is the most significant language change in C++17. The standard legalese in P0135 is complicated, but in a nutshell it means that copy elision in several specific contexts is now mandatory. In practice, the biggest change is that you can now return non-copyable and non-moveable objects (like std::mutex) from a function by value.
    Guaranteed copy elision
  • The definition of an aggregate type has been extended in C++17 to allow non-virtual public base classes (P0017). This means that you can now use aggregate initialization with such classes:
    Aggregates with bases
  • std::is_aggregate is a new type trait introduced in C++17 as a way to check whether a type is an aggregate type.
    is_aggregate type trait
  • __has_include (P0061) is a builtin preprocessor macro which can be used to portably determine whether or not a library header is available for inclusion. For example, here is how you can select a coroutine-based generator either from the standard library if it provides one or from CppCoro:
    __has_include example

With the progress done over the course of the previous releases (see our updates about C++17 support in 2017.1, 2017.2, and 2017.3), these changes mean that most of the major C++17 features are now supported by ReSharper C++. The biggest gaps that we are going to focus on next are limited support for evaluation of constexpr functions (RSCPP-18417), hexadecimal floating point literals (RSCPP-20364), and noexcept as a part of the function type (RSCPP-20285).

C++20 features

While it’s too early to say for sure which changes are going to make it into C++20, the new standard is already shaping up and its features are becoming available in major compilers. Keeping up with the evolution of the language, ReSharper C++ now supports several features from the upcoming standard:

  • Even though coroutines have not been officially accepted into C++20 yet, the Coroutines TS is already implemented in both MSVC and Clang and is used by many real-world projects.
    ReSharper C++ understands and resolves all the new syntax introduced by the proposal, including co_await and co_yield expressions, co_return statements, range-based for co_await loops, and operator co_await. If you invoke Go to Declaration on a coroutine expression or statement, ReSharper C++ will let you navigate to all the functions which are called behind the scenes by the low-level coroutine machinery.
    Coroutines navigation
    Remember that you need to use the /await compiler switch to enable coroutines support. Please note that the <experimental/generator> header provided by Visual Studio does not fully conform to the latest Coroutines TS draft. If you need a library of coroutine-based abstractions, we recommend using the excellent CppCoro library by Lewis Baker.
  • Designated initialization (P0329) introduces a new syntax based on C99 to initialize an aggregate class using explicit names of data members.
    Designated initialization
  • Similar to if and switch statements with initializer from C++17, range-based for statements will allow an initializer block in C++20 (P0614). This change lets you create a declaration with the same lifetime as the for loop.
    Range forwith initializer
  • Feature test macros (P0941) are a set of predefined macros which can be used to check in a portable way if a particular language feature is supported. They complement the C++17 __has_include macro.
    Feature test macros
  • Bit-fields can now have default member initializers (P0683), similar to normal class members.
    Bit-fields with initializers

Integrated spell checking with ReSpeller

ReSharper C++ 2018.2 provides spell-checking functionality out of the box, thanks to the newly bundled ReSpeller extension which has also been updated to support the C++ language. Just like with code analysis, ReSpeller scans for spelling mistakes and typos in identifiers, comments, and string literals, and provides quick-fixes to resolve these problems.
ReSpeller

When you encounter a spelling mistake, you can invoke the Alt+Enter menu and ReSpeller will provide two options to fix the mistake:

  • The first option is to fix the typo. If the typo was in the name of symbol, the Rename refactoring will be automatically invoked. If the rename operation is local, you will get a list of proposed corrections in a dropdown menu. With a global rename operation you will need to clear the Name field and invoke completion with Ctrl+Space to get the same list.
  • The second option is to add the unknown word to ReSpeller’s dictionary. As with other preferences, you can choose one of the settings layers to save the word to.

Code understanding is what really makes spell-checking stand out in ReSharper C++ compared to other Visual Studio extensions. If ReSpeller encounters a mistake in an identifier name, it will only be reported at the declaration point. Documentation comments are handled in a special way too, so that Doxygen commands are skipped. Furthermore, the Environment | ReSpeller options page allows you to make ReSpeller skip locals, overriding member function, or class members with specific accessibility.
ReSpeller options

By default, the spell-checker comes with a built-in dictionary for American English, so do not be surprised if ReSpeller complains about “colour” or “behaviour”. Dictionaries for other languages can be easily added too, since ReSharper C++ uses the standard hunspell dictionary format. For instructions on adding a new dictionary and more info about ReSpeller, see Integrated spell checking with ReSpeller in ReSharper and Rider.

Formatting inspections

Every now and then, you want to be notified directly in the code when you are not following formatting rules. With this in mind, ReSharper C++’s code formatting engine introduces inspections and quick-fixes for formatter-related problems: inconsistent indenting, line breaks, spaces, and blank lines can now be observed and fixed directly in the code editor.
Formatting inspections

By default, formatting inspections are disabled so as not to bother anyone who doesn’t care about formatting during typing. Go to ReSharper | Options | Code Inspection | Inspection Severity | C++ | Formatting to see all the available inspections and select severity levels for those you wish to be notified of.
Severity of formatting inspections

To learn more, see Maintaining consistent code style with formatting inspections.

Other changes

ReSharper C++ 2018.2 brings many smaller improvements in different areas:

  • When performing size and alignment calculations, the code analysis engine takes into account bit-field sizes, alignas specifiers, and __decltype(align) attributes.
    Bitfield sizes and alignment
  • Parameter Info provides details about members of the aggregate class when performing aggregate initialization.
    Parameter info for aggregates
  • Comments in a code file to override formatter settings can be generated directly from the Configure Format dialog.
    Configure format
  • You can navigate to the begin() and end() functions used in a range-based for loop by invoking Go To Declaration on the colon character.
    Navigation in range-based for loop
  • Separate color settings for static class fields and static member functions were added. You can customize them by going to the Fonts and Colors Visual Studio options page and  changing two display items, ReSharper C++ Static Field Identifier and ReSharper C++ Static Member Function Identifier.
  • Expected failures specification is supported in Boost.Test unit tests.
    Boost.Test expected_failures attribute
  • A lot of performance fixes in different areas of ReSharper were made, from speeding up ClangFormat support to decreasing solution loading time. More detailed information is available in the performance blog post series dedicated to the ReSharper 2018.2 release.
  • 200+ issues were fixed over the course of ReSharper C++ 2018.2 development, including two important issues where ReSharper C++ could sometimes fail to parse files with complicated macro expansions, and where it missed some usages when performing usage search.

CppCon 2018

CppCon 2018
ReSharper C++ is coming to CppCon 2018, the premier C++ conference! Please stop by the JetBrains booth to have a chat about our products and grab some cool swag, and consider attending one of the many talks presented by our colleagues:

We’ll also run a Tool Time lab on Tuesday, September 25. We are looking forward to seeing you there!

As usual, please share your feedback with us and report issues either in the issue tracker or on the support forum.

Download ReSharper C++ 2018.2

image description