What’s New in ReSharper C++ 2016.2

As a part of ReSharper Ultimate 2016.2, our C++ team is happy to present the ReSharper C++ 2016.2 update. All in all, the new release comes with 200+ fixes and resolves several important performance- and stability-affecting issues. Let’s take a tour of the new features in this release.

Inline Variable

The mainline ReSharper’s refactorings continue to make their way into ReSharper C++. With the latest update, Inline Variable is now available for C++. This refactoring allows you to replace all occurrences of a variable in the code with its initializer. (The reverse functionality is already provided by the Introduce Variable refactoring.)
Inline Variable refactoring for cpp

Doxygen support

Doxygen is arguably the most popular format and tool for code documentation in the C++ world. ReSharper C++ now understands Doxygen syntax, and provides several key features to facilitate editing of documentation blocks:

  • Typing assist helps with creating new comment blocks and maintaining the structure of existing ones.
  • Code completion suggests Doxygen commands with accompanying short descriptions.
    Doxygen completion
  • Function parameter references introduced with \param commands will be reported by Find Usages and will get updated when Rename is used to change a function parameter’s name.
    Rename \param
  • Warnings are issued when function parameter references do not resolve to an existing function parameter.
    Unresolved \param

Documentation generation

You can now generate documentation for C++ declarators, classes and macro definitions. Since parsing a C++ file can require a significant amount of time, to avoid UI freezes this feature is implemented via a context action available when using Alt+Enter on the entity’s name.
Document context action
When the action is applied, ReSharper C++ uses the builtin doc live template to generate the resulting comment. The default documentation template is configured to be compatible with Doxygen syntax, but it can be customized (as usual) using the Templates Explorer tool window. An assortment of specialized documentation macros can be used inside the template, which evaluate to:

  • Short or qualified name of the entity that is being documented.
  • Function/macro/template parameter name or type (the containing template line is duplicated for each corresponding parameter).
  • Function return value, if there is one.

Quick Documentation

Thanks to Doxygen support, Quick Documentation now works in C++. The documentation pop-up (bound to Ctrl+Shift+F1 in the Visual Studio scheme or Ctrl+Q in the IntelliJ IDEA scheme) will display documentation from Doxygen comment blocks, or the symbol’s signature if no documentation is found.
Quick documentation pop-up

Code analysis

ReSharper C++ now understands several of the standard C++11 attributes and their Visual C++ counterparts:

  • Usages of functions and classes marked with [[deprecated]]/__declspec(deprecated) are reported together with the specified reason.
    Highlighting of a deprecated function
  • Not all control paths return a value and other control-flow based analyses correctly handle functions marked with [[noreturn]]/__declspec(noreturn).

Most header files should start with some form of include guard to avoid multiple inclusion. Similar to the Missing precompiled header include for .cpp files, ReSharper C++ will now warn you if a header file lacks an include guard and will provide a fix to automatically add a #pragma once directive.
include_guard

Omitting noexcept specifications from user-defined move constructors and assignment operators can have serious performance implications (for an in-depth discussion refer to this blog-post or Item 14 of Scott Meyers’ excellent “Effective Modern C++”). To make sure this is intentional, ReSharper C++ will warn you about move constructors, move assignment operators and swap functions without an explicit noexcept specification, with corresponding fixes to add one.
Move constructor without noexcept

Starting with Visual Studio 2013, the Visual C++ compiler has supported explicit user defined conversions. To complement the existing Non-explicit converting constructor inspection, Non-explicit conversion operator was added. Severity for both analyses is set to Hint by default (so they are not shown as suggestions), but can be increased if you prefer to avoid implicit user-defined type conversions.
Non-explicit converting constructor

In addition to suggesting to replace zero constants with nullptr in pointer contexts, ReSharper C++ will also offer replacing integral constants with true/false in boolean contexts.
Replace expression with true

Last but not least, another new inspection detects missing default cases in switch statements and provides a fix to insert it. The same fix is also available for the Uncovered enumerators inspection.
Default case

Go to Text

A new member of the Go to family, Go to Text navigation (Ctrl+T,T,T in the Visual Studio keyboard scheme or Ctrl+N,N,N in the IntelliJ IDEA scheme), lets you quickly find and navigate to any text in source and textual files in the entire solution.
Go to text
This new feature uses trigram indexing to make text search blazing-fast. Similar to other navigation commands, if there are too many matching items you can press + on the numeric keypad to explore results in the Find Results window.

New code style options

New formatter options provide support for some commonly used styles in C++ code:

  • The Braces Layout | Keep simple compound statements in one line setting was added to allow single-line definitions of trivial functions. It can be set to force ReSharper C++ to make such functions single- or multi-line, or to simply not change their formatting.
    Keep simple compound statements in one line
  • A related setting, Blank Lines | Around single line function definitions, controls the number of blank lines that a single-line function should be surrounded with.
  • The Wrapping and Aligning | Break line before member initializer list option controls whether to start member initializer lists on a new line.
    Break line before member initializer lists

Different projects use different conventions for the syntax of #include directives – as a result, we received several requests to make auto-generated #include directives more customizable. ReSharper C++ now provides preferences about whether to insert paths relative to the current file and when angle brackets should be used instead of quotes.
Include directives settings

A couple of settings were added specifically for compatibility with pre-C++11 codebases:

  • Formatter gets an option to require a space between closing angle brackets in template arguments, to avoid a notorious parsing issue in C++98.
    Space between closing angle brackets in template arguments
  • Instead of nullptr, ReSharper C++ can be configured to use NULL or 0 for default pointer initializers.
    Default pointer initializer

Generate improvements

In addition to Google Mock, the mock function generator now supports Trompeloeil. Trompeloeil is a modern header-only C++14 mocking framework, and is a great alternative to Google Mock when your project needs a mocking library but does not use Google Test. As with Google Mock, the generator becomes available when ReSharper C++ detects that the library is included into the current source file.
Trompeloeil mocks

Several existing code generators received new options:

  • To complement the related code analysis, copy/move operations and swap function generators allow making generated functions noexcept.
  • Similar to relational operators, the equality operator generator now has an option to use std::tie.
  • The constructor generator now lets you specify the accessibility of generated constructor(s) (starting with ReSharper C++ 2016.2.1).

Auto-import completion

Code completion in C++ became integrated with auto-import and can suggest symbols that are not included into the current file. The necessary #include directives are added automatically when an auto-import item gets used.
Import suggestions in C++ auto-completion
Please note that auto-import items get added into the completion list asynchronously, so they will be available after a short delay.

Code template enhancements

If you need to surround a piece of code with a template, just select the code and type in the name of the template you need: no extra shortcuts required. Furthermore, a single template can now be used for creating code (as a live template) and for surrounding existing code (as a surround template).
Surround templates

The default C++ class and struct file templates now contain a macro that expands into an #include directive for the precompiled header file, if the project uses one.

Odds and ends

Keeping up with the language evolution, ReSharper C++ extends its support of the C++14 standard. In particular, variable templates and decltype(auto) are now supported.

When your caret is on one of the exit points of a function/loop/switch (return, throw etc.), ReSharper C++ will automatically highlight all other exit points.
highlighting_exits

Similar to Visual Studio’s __INTELLISENSE__ define, ReSharper C++ now defines its own __RESHARPER__ macro in the internal preprocessor implementation. If necessary, this definition can be used to guard code that ReSharper C++ does not understand for some reason, or to hide parts of a file from code analysis.
__RESHARPER__ define

CppCon 2016

If you are attending CppCon 2016, be sure to stop by the JetBrains booth September 20-21! Members from both the CLion and ReSharper C++ teams will be present, and we will be happy to tell you all about our products, share future plans and answer your questions. Don’t miss your chance to participate in our license raffle and win a free 1-year subscription for any JetBrains C++ product of your choice!

CppCon 2016

As always, we would like to hear your feedback – and if you have any problems or feature suggestions, do not hesitate to contact us or create a request in our issue tracker!

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

3 Responses to What’s New in ReSharper C++ 2016.2

  1. Даниил Водопьян says:

    Will Project Rider use Resharper C++ or InteliJ C++? Why? 😉

    • Igor Akhmetov says:

      No decision has been made yet. Our foremost goal with project Rider is to provide a great cross-platform .NET experience.

  2. Pingback: What’s New in ReSharper C++ 2016.3 and 2017.1 - ReSharper C++ BlogReSharper C++ Blog

Leave a Reply

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