What’s New in ReSharper C++ 2017.2

Please welcome ReSharper C++ 2017.2! This is the second annual ReSharper C++ release, packed as usual with new features and bug-fixes.
ReSharper C++ 2017.2

Take a look at the What’s New page for a quick overview, or continue reading for a deep dive into the highlights of this release:

Language understanding

ReSharper C++ 2017.2 has finalized support for several C++11 features:

  • In addition to user-defined integer literals, ReSharper C++ supports floating-point, character, and string literals. Find Usages and Rename were also updated to handle literal operators.
    Rename of a literal operator
  • C++11 extended friend declarations are recognized.
    Extended friend declarations
  • Expression SFINAE support was improved in several ways. Most importantly, overload resolution results are now checked inside expressions during template substitution.
    Substitution failure inside an expression
  • More standard type traits are supported, including all traits with names prefixed by is_trivially.

Visual Studio 15.3 comes with a significant update for its C++ toolset. The following new C++17 features introduced in 15.3 are now also supported by ReSharper C++:

  • Selection statements with initializer (P0305R1) — the extended syntax for if and switch statements which allows initializers:
    If with initializer
  • Code inspections understand the C++17 attributes [[nodiscard]] (P0189R1) and [[maybe_unused]] (P0212R1):
    [[nodiscard]] and [[maybe_unused]] attributes
  • Using attribute namespaces without repetition (P0028R4):
    Using attribute namespaces without repetition
  • Lambda capture of this by value (P0018R3):
    Lambda capture of this by value

Unfortunately, structured binding declarations from C++17 are not yet supported, but they are top-of-the-list for our next release.

On a related note, another important change in the 15.3 toolset is partial support for two-phase name lookup. It has to be manually enabled through the /permissive- conformance switch, but MSVC’s team plan is to turn conformance mode on by default in the next major compiler revision. If you want to move your code forward and make it fully two-phase clean, ReSharper C++ can be a great aid since it has been using two-phase name lookup since the beginning. You just need to pay attention to warnings inside template code—for example, ReSharper C++ will point out lookup errors during the first phase of lookup:
Two-phase name lookup
For help with errors related to two-phase name lookup, we have suggestions about missing template and typename keywords in dependent code:

There is some news about C support as well. ReSharper C++ now implements anonymous structures, a Microsoft C extension that allows declaring a structure variable within another structure without giving it a name. Members of anonymous structures can be accessed as if they were members in the containing structure. This extension is limited to C only, but it is supported both by Clang and GCC with the -fms-extensions option.
Anonymous structs

If you need to override a few functions from a base class, there is now an alternative to using the Generate overriding members dialog. Virtual functions that can be overridden will be included into the completion list when you complete inside a class body. When selected, these completion items will insert a full function declaration. To continue, you can use Generate implementation or Generate inline implementation – either context action will create a function body.
Override functions in completion

Finally, the Generate constructor dialog got a new option, Make empty constructors = default. As the name suggests, with this option enabled ReSharper C++ will = default the generated constructor when it is empty, so it’s a quick way to add a defaulted constructor if you need one in your class.

Code inspections and quick-fixes

ReSharper C++ 2017.2 adds several new code inspections:

  • The much-requested Inconsistent Naming inspection detects violations of naming style in your code, and the accompanying fix allows you to quickly invoke the Rename refactoring with the name changed according to the corresponding naming rule. By default, the naming inspection has the Hint severity, which means that naming inconsistencies do not appear on the marker bar and are not highlighted with curly underlines. If you want to enforce naming rules and find that this inspection is useful, do change its severity to Suggestion or Warning.
    Inconsistent naming inspection
    Naming rules used by the inspection can be configured on the Code Editing | C++ | Naming Style options page. This page has been reworked since the previous release and now allows adding new names rules and editing existing ones. The rules are checked in reverse order, meaning that a rule that comes later in the list has higher priority than the one before it.
    Naming style
    For each naming rule, it is possible to specify the kinds (e.g. class, function or variable), accessibility, and specifiers (static, const, constexpr or volatile) of entities to which the rule should apply.
    Naming rule editorPlease note that the naming rules for getters and setters, which are present in previous versions of ReSharper C++, are now gone. You can use new options in the Generate getters and setters dialog instead to control whether or not to add is/get/set prefixes to getter and setter names.
  • One of the unique ReSharper C++ inspections is Member function may be const, which highlights functions that do not change member variables of the containing class and thus can be marked as const. ReSharper C++ 2017.2 adds a couple of related inspections, Local variable may be const and Parameter may be const (since 2017.2.1), which perform a similar analysis and show local variables and function parameters that can be made immutable.
    Add const fix
    If you consider using const everywhere possible as too excessive, reduce the severity of one or both of these inspections.
  • Unused entity inspections used to work only with local variables and function parameters. Their scope has been extended now to also include global variables, classes, enums, and enumerators that have internal linkage or are members of an anonymous namespace.
    Unused entity inspection

A number of new quick-fixes for existing inspections were also introduced:

  • Add #pragma once is the recommended fix when an include guard is missing in a header file. There are teams though that prefer using #ifndef/#define/#endif include guards, and ReSharper C++ now has a fix that wraps the header file with this combination of directives.
    Include guard fix
  • If there is an unused expression without any side effects inside a function of a type compatible with the function’s return type, ReSharper C++ lets you convert it into a return statement via the Return unused expression fix.
    Add return fix
  • Trying to bind lvalue expressions to rvalue references is a compiler error, but sometimes it just means that a call to std::move was intended but is missing. To quickly add it, use the new Add std::move fix.
    Add std::move fix

ClangFormat support and line wrapping

ReSharper C++ 2017.1 brought support for EditorConfig, a popular standard for defining code formatting preferences. In the C++ community, however, ClangFormat is the de facto standard for formatting tooling. ReSharper C++ 2017.2 adds support for reading ClangFormat configuration files, so if there is one in your project, ReSharper’s code formatting engine will automatically pick it up and use it. To find the configuration files that affect a particular file, ReSharper C++ looks for .clang-format and _clang-format files in the containing folders. ReSharper C++ will also help you understand exactly which style options are applied and where they come from:

  • You will see a yellow warning on ReSharper C++ formatting options pages if at least one preference on a page is overridden by ClangFormat options. Each overridden preference will be also highlighted with yellow:
    ClangFormat in options
  • You can see and study all ClangFormat configuration files that affect the current file in the File Formatting Info window:
    File formatting info window

Please refer to the Using Clang-Format help page for the full list of supported ClangFormat style options.

Another big change related to code formatting is support for line wrapping. You can find the option to turn it on or off, as well as a collection of options that control wrapping inside different syntax elements, in the Line wrapping group on the Code Editing | C++ | Formatting Style | Line breaks and Wrapping options page.
Line wrapping options

A number of new formatting options were added, in particular options that control:

  • line breaks after template headers and function return types;
  • indentation of parentheses and their contents in function declarations, function calls, and if/while/for statements; and
  • spaces around colons in range-based for loops and in lists of base classes.

Go to declaration now works inside the bodies of macro definitions. Of course, due to the textual nature of preprocessor macros, the results of such a context search are tentative. For macro parameters, the search will jump to the parameter declaration. For other identifiers inside macro bodies, all symbols inside the solution with names that match the identifier will be shown.
Declaration search inside macro bodies

Go to Everything (Ctrl+T), Go to File Member (Alt+\) and Go to Action (Alt+Enter) have been improved as follows:

  • The query syntax got extended in several ways. ReSharper will now match identifiers even if the word order inside your query is mixed up:
    Word order
    On the other hand, if you add quotes around a search query, ReSharper will only look for exact matches. If you need even more control, it is also possible to combine exact search with wildcard characters like * and ?.
    Exact search
  • To streamline the navigation experience, Go to Text is integrated into Search Everywhere, so you do not need to deliberately use Go to Text to get text matches in search results.
  • A laptop-friendly Shift+Enter shortcut can now be used in addition to Num + to open search results in a separate Find Results tool window, where you can explore and filter items more easily.

Navigate to file nearby is a completely new navigation feature, which displays project structure around the current file in a popup menu. The top-level menu shows the solution, the current project, containing folders, and files in the same folder. From there you can navigate deeper, open files, and create new files and folders. Navigate to file nearby is not bound to a key shortcut by default, but it can be invoked similar to other navigation actions from the Navigate To context menu (Alt+Backquote) or via ReSharper | Navigate | Go to File Nearby.
Go to file nearby

For more information about platform-wide changes in navigation, please see ReSharper 2017.2 – what’s new in navigation?.

Performance improvements

ReSharper C++ 2017.1 introduced the option to not reindex includers when preprocessor directives in a header file get modified. In the 2017.2 release, another common situation which caused bulk reindexing is addressed using a similar mechanism. By default, ReSharper C++ will now not reindex files after the current build configuration of a project is changed. Please note that code inspections may execute slower after a configuration change the first time you open a file, since ReSharper C++ will need to reparse the included files. If you prefer the old behavior, you can revert via the option Code Editing | C++ | Performance | Reindex affected files after a project or a file property is changed.

The second performance-related change is added support for the new asynchronous Visual Studio API for reading project properties, available starting with Visual Studio 15.3. In the past, ReSharper C++ had to query project properties on the main thread, which could lead to UI stalls when you opened your solution or changed project configurations. These freezes should be gone now, with the additional benefit of lower memory usage for storing project properties. Moreover, the lightweight solution load Visual Studio feature is now supported, and ReSharper C++ should no longer force loading of all projects in the solution even when LSL is enabled. If you encounter ReSharper C++ issues when running Visual Studio 15.3, please try disabling the option Code Editing | C++ | Performance | Read project properties asynchronously in Visual Studio 15.3 and later and reopening the solution. If it does help, do let us know!

CppCon 2017

CppCon 2017
This year’s biggest C++ conference takes place in Bellevue, Washington, USA on September 24–29. JetBrains is proud to return as a bronze sponsor and will have an exhibition booth set up on the 27th and 28th. If you’re there, stop by the booth to have a chat with members of our CLion and ReSharper C++ teams, give them your feedback, and consider attending one or more of the talks delivered by JetBrainers:

  • New standards to the rescue: the view through an IDE’s glasses, by Anastasia Kazakova (CLion Product Marketing Manager) at 2 pm, September 25.
  • Tools from the C++ eco-system to save a leg, by Anastasia as well at 3:15 pm, September 26.
  • The Holy Grail—A Hash Array Mapped Trie for C++, by Phil Nash (JetBrains developer advocate and the author of the famous Catch unit testing framework) at 9 am, September 29.

We are looking forward to seeing you there!

That’s it! Start your free 30-day evaluation and try out all the new features and fixes. As always, please leave us any feedback and report issues either in the issue tracker or on the support forum.

Download ReSharper C++ 2017.2

This entry was posted in ReSharper C++ Tips & Tricks and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *