What’s New in ReSharper C++ 2017.3

ReSharper C++ 2017.3 has been one of our biggest updates yet in terms of both new features and fixed issues.
ReSharper C++ splash
Without further ado, let’s dig into the notable changes it brings:

Clang-Tidy integration

Clang-Tidy is a powerful open-source code analysis tool based on the popular Clang compiler. It comes with an extensive set of code checks and accompanying fixes for typical programming errors.

ReSharper C++ 2017.3 provides seamless integration with Clang-Tidy. This means that as you edit a file, ReSharper C++ runs Clang-Tidy on it in background as a separate process, with inspection results shown right in the editor alongside other ReSharper C++’s inspections. Unsaved files are handled transparently by saving the text of the current document to a temporary file and instructing Clang-Tidy to use it instead of the on-disk version.

To distinguish between Clang-Tidy checks and ReSharper C++’s inspections, look at the name of the check in square brackets, appended to the inspection message.
Clang-Tidy inspection

In addition to diagnostics from Clang-Tidy checks, Clang-Tidy also issues diagnostics from Clang Static Analyzer and warnings provided by the Clang compiler itself. All of them have corresponding ReSharper inspections with configurable severity levels, which can be adjusted to meet your needs on the Inspection Severity options page.
clang-tidy inspection severity

Some of the Clang-Tidy checks that duplicate ReSharper C++’s built-in inspections are turned off by default. In addition, all static analyzer checks are disabled, since enabling them significantly slows down Clang-Tidy.

As with the built-in inspections, you can use the inspection context menu to quickly change the severity of a Clang-Tidy check, or to disable it via a comment. There is also an additional action that opens the online documentation page for a particular check.
clang-tidy inspeciton menu

ReSharper C++ lets you apply the fixes provided by Clang-Tidy similarly to its own built-in quick-fixes. As with other bulk fixes, Clang-Tidy fixes can be applied individually or inside a specific scope (file, folder, project, or solution).
clang-tidy fix

By default, ReSharper C++ will reformat code changed by Clang-Tidy to maintain the code style. This behavior can be disabled via the Reformat changed code after applying Clang-Tidy fix-its setting to speed up fix execution.

Clang-Tidy fixes can also be applied from code cleanup. Built-in code cleanup profiles do not include the Clang-Tidy stage, so to enable it you need to create a new profile and select the Clang-Tidy checks which will be enabled during a code cleanup run.
clang-tidy code cleanup

The selected checks will be enabled even if they are turned off on the Inspection Severity options page. Please be careful when enabling too many checks at once — code cleanup runs Clang-Tidy only once for a given file, so if multiple fixes touch the same block of code, the changes might conflict with each other.

ReSharper C++ does not write its own Clang-Tidy config, so a user-provided one can be picked. Clang-Tidy attempts to read configuration for each source file from a .clang-tidy file located in the closest parent directory of the source file. The source file here (as with the rest of ReSharper C++ inspections) is the .cpp file itself if the analysis is run on it, or a random .cpp file which includes the header when the analysis is performed on a header file. Alternatively, you can use the Clang-Tidy config ReSharper setting to pass a string with custom configuration to Clang-Tidy via the -config command-line option.

The -checks command line option is used to pass the list of enabled checks to Clang-Tidy, which then gets appended to the value of the checks option read from the Clang-Tidy config. To construct the -checks argument, ReSharper C++ takes the value of the List of enabled/disabled Clang-Tidy checks and appends to it the names of checks which are turned off on the Inspection Severity options page.

We needed to make a few modifications to Clang-Tidy to facilitate its usage from the IDE, so unfortunately a custom Clang-Tidy binary cannot be used at the moment. ReSharper C++ 2017.3 is shipped with a version of Clang-Tidy built from the trunk, and we plan to update it to the final Clang 6.0 version in ReSharper C++ 2018.1.

There are a few caveats to Clang-Tidy integration that we are aware of:

  • Files using UTF-16 or UTF-32 encoding cannot be read by Clang and thus are not supported by Clang-Tidy at the moment.
  • Sometimes Clang-Tidy might crash on your code, and Windows will show you the “Process has stopped working” message. In this case please disable Clang-Tidy integration for the current solution (see how below). We’ll update the bundled binary in 2018.1 so that this message is not shown.

There are several ways to disable or enable Clang-Tidy integration:

  • Via the Enable Clang-Tidy support setting in ReSharper options.
  • Through the Enable Clang-Tidy analysis toggle in the status indicator context menu:
    Inspection menu
  • With the Ctrl+Shift+Alt+9 keyboard shortcut.

Debugger features

ReSharper C++ 2017.3 is the first release that brings debugger-related features to the table. The most useful of them is inline watches: ReSharper C++ will display local variables, function parameters, current line expressions, and function return values right inside the editor. This feature provides immediate feedback during debugging sessions, which means that often you don’t even have to consult the Watches or Autos tool windows.
Debugger features
ReSharper C++ is careful to evaluate only those expressions that do not have side effects. At the moment, expression evaluation is limited to references, constants, member access, and built-in subscript operators. Subscript operators of std::vector and std::array are also evaluated as an exception. Please note that inline watches use the Visual Studio debugger engine to evaluate expression, which means that Natvis files with user-provided visualization rules are automatically supported.

ReSharper C++ also comes with its own debugger DataTips, which provide several advantages over their Visual Studio counterparts:

  • You can quickly search for a string inside a DataTip (just start typing with the DataTip open).
  • You can mark members of a class which will be used to construct a custom presentation string for objects of this class. To do this, invoke Highlight Property from the context menu on class members that you are interested in.
  • Unlike Visual Studio DataTips, ReSharper DataTips do not disappear when the mouse pointer leaves the DataTip window area.

ReSharper DataTips
To access ReSharper DataTips, just click the inline value display. If you find ReSharper DataTips helpful, you can replace Visual Studio DataTips with ReSharper’s by enabling Override VS DataTips with ReSharper DataTips on the Tools | Debugger ReSharper options page.

Working with multiple breakpoints should now become easier. The new Go to Breakpoint action (Ctrl+Alt+F9) displays breakpoints in a context menu so that you can quickly navigate between them. In addition, the dedicated R# Breakpoints tool window (ReSharper | Windows | Breakpoints) groups breakpoints and displays the line of code where each breakpoint was set.
Breakpoints tool window

Breakpoints and tracepoints can also be created directly in the Find Results tool window, from the occurrence context menu.
Breakpoints from find results

But that’s not all — we are working on adding new debugger-related features. In particular, ReSharper C++ 2018.1 will bring debug step filters, a feature which lets you make the debugger step over certain functions (e.g. subscript operators or trivial getters). If you are interested in trying it, head over to the Early Access Program page when the EAP starts and install the latest available ReSharper 2018.1 build.

Language understanding

For the 2017.3 release, we specially focused on improving the product’s understanding of C++. We made sure the following new C++17 and C++14 features received support:

  • C++17 structured binding declarations allow declaring multiple variables that bind to subobjects of another object. This is particularly useful when working with functions that need to return multiple values. As with other identifiers, you can determine the actual types of structured bindings via ReSharper C++’s tooltips or the Quick Documentation popup.
    Structured bindings
    Structured binding declarations support binding to array elements, public class data members, and tuple-like objects. Making your own classes support the tuple-like binding protocol requires specializing std::tuple_size and std::tuple_element, and if something goes wrong, ReSharper C++ will provide you with detailed error messages.
    Error in structured bindings declaration
  • Return type can now be deduced for C++14 auto functions without trailing return types.
    Auto function without return type
    Supporting this language feature was rather complicated because, to determine the return type of a function declared in a header file, its body is needed. On the upside, implementing it also allowed us to fully support C++17 constexpr if statements, which can cause a function to have different return types depending on which constexpr if branch is chosen.
    constexpr_if_preview
  • Type checking and return type deduction now work for lambda expressions, including support for C++14 generic lambdas.
    Generic lambda
  • Previously only functions could be declared as inline, but in C++17 variables can be declared inline too. This is now supported by ReSharper C++, and a warning will be issued when the inline specifier is required to avoid linking errors.

All in all, this brings ReSharper C++ almost to the level of standard C++ support provided by the Visual C++ compiler at the moment, with two notable features still in our queue to implement — fold expressions and evaluation of constexpr functions.

Other language-related changes include:

  • ReSharper C++ now understands include_alias pragma directives, which allow mapping any header filename to another.
    include_alias pragma
  • Improved support of explicit template instantiations. In particular, explicit instantiations of both class and function templates are now handled correctly by the Rename refactoring, and can be navigated to via gutter icons.
    Explicit instantiations
  • Support for the native event handling Microsoft C++ extension.
    Native event handling

Code inspections and context actions

ReSharper C++ 2017.3 extends its set of available code inspections:

  • Binary operators with suspiciously looking identical or equal operands will be highlighted.
    Equal operads of a binary operator
  • Default arguments on virtual functions are considered bad style (see e.g. Google’s C++ style guide for details). ReSharper C++ now includes an inspection which finds redefinitions of a default argument from a base function.
    Default argument in a virtual function
  • const and volatile specifiers on parameters in a function declaration have no effect and will be shown as dead code.
    Const parameter in a function declaration
  • Function parameters that are not mentioned in the function documentation comment will be underlined, with a fix to insert the corresponding documentation line.
    Generate parameter documentation
  • Member initializers in constructors that duplicate the corresponding default member initializers will be marked as redundant.
    Redundant member initializer
  • All user-defined literal suffixes must start with the underscore character according to the C++ standard. ReSharper C++ will warn you about literal operators that violate this requirement.
    Invalid user-defined suffix

A couple of context actions were also added:

  • An action to move a member initializer from a constructor member initializer list to a default member initializer.
    Move initializer action
  • An action to switch between class and typename keywords in type template parameter declarations.
    Switch between class and typename

Code formatting

If you wish to preserve custom formatting just inside a block of code, ReSharper C++’s formatter can now be selectively disabled by wrapping this block with a pair of comments containing formatter directives: // @formatter:off to disable formatting, and // @formatter:on to enable it back.
How to turn off the formatter
Instead of disabling the formatter completely, you can configure it using inline EditorConfig-style settings and override only one or several of them, keeping common code style settings active. Please refer to the EditorConfig Properties help page for the list of supported properties.
Configure the formatter with comments

Another long-requested formatter feature is the ability to align specific code elements in columns, which is now supported for assignment statements, declaration names, and single-line comments (configured by a family of settings in Indentation and Alignment | Align Similar Code In Columns).
Multiline formatting

There’s also a related multiline alignment setting, which controls the outdenting of command and member access operators in chained method calls.
Outdent member access

The layout of linkage specification blocks can now be customized via two formatting settings, Indentation | Indent linkage specification block members and Braces Layout | Linkage specifications. The usual idiom of using extern "C" blocks in header files to create an API compatible with C is now supported:
Linkage specification

Finally, two new settings, Spaces | Before/after commas in uniform initialization braces and Spaces | Before end of line comment, provide more options to match spacing in your code.

The Go to Declaration command is now available on dependent names inside definitions of templates. This should make it much more useful in template-heavy code. Since ReSharper C++ has no way of finding the exact entity that the name refers to, instead it will look through all the symbols and offer those with matching names and signatures as potential navigation targets.
Dependent names in goto declaration

In addition, Go to Declaration now lets you navigate from a member function definition to a declaration with a non-matching signature if no matching declaration is found. This ability comes in handy when you change the definition and need to update the declaration (even though we encourage you to use the Change Signature refactoring and related fixes for this purpose).
Goto mismatched declaration

To-do patterns get a URL field, which creates a link in your code for navigating to external resources by Ctrl+Click on the to-do item, or via the Alt+Enter shortcut. This helps you keep your to-do comments brief and straightforward: no full URLs are needed, only an issue ID. Links in to-do items support the Peek Preview feature to display the linked issue inline in the editor. Also, you can easily locate the to-do item in To-do Explorer via the Alt+Enter menu.
Linking from to-do items

Smaller navigation-related changes include:

  • Search Everywhere always shows text matches in a dedicated section, even when there are other results. So, you do not need to switch to Go to Text when you want to take a peek at text occurrences.
    Goto text
  • When occurrences are shown in the Find Usages window, ReSharper C++ considers and presents the context (e.g. function calls or return statements) from the surrounding lines.
    Multiline occurrences
  • The redesigned preview pane in ReSharper tool windows (shown above) and formatter options pages are now based on the Visual Studio editor. This gives preview pane code a more natural look: keywords and strings are highlighted, identifier colors are applied, and font settings and scaling are inherited from Visual Studio’s text editor settings.

Other changes

  • Catch2, the latest version of the popular Catch unit testing framework, is now supported. Its codebase has been updated to use C++11, with strong focus on both compile and runtime performance. If you are interested in learning more about new Catch2 features and Catch in general, a good place to start would be the announcement blog post and the Modern C++ testing with Catch2 talk by Phil Nash, the author of Catch.
  • The Performance Guide page in ReSharper options collects a set of Visual Studio and ReSharper settings that might affect overall performance in one place and provides a way to quickly change them.
    Performance guide
    While it does not have any C++-related tips yet, it can still help you improve the general responsiveness of your development environment.
  • Generative completion now allows creating definitions not only for member functions, but also for free functions.
    Generative completion
  • Built-in live templates cctor and mctor which expand to a copy and move constructor, accordingly, were added.
    cctor_preview
  • We’ve added the setting Use trailing return types in generated function declarations (in ReSharper | Options | Code Editing | C++) for trailing return types afficionados. When it is enabled, various code generation features will create function declarations with trailing return types instead of using the classic return type style.
  • Numerous performance issues were resolved. Most importantly, typing assist and completion lags in Visual Studio 15.5 and slow renaming of files were addressed. Additionally, nested queries in Go to Symbol should execute much faster now.

We hope you find the new features useful! Please leave us any feedback and report issues either in the issue tracker or on the support forum.


Download ReSharper C++ 2017.3

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

One Response to What’s New in ReSharper C++ 2017.3

  1. Pingback: What’s New in ReSharper C++ 2018.1 - ReSharper C++ BlogReSharper C++ Blog

Leave a Reply

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