What’s New in ReSharper C++ 2016.3 and 2017.1

ReSharper Ultimate 2017.1 is out! It’s been some time since our last post about updates in ReSharper’s C++ support, so let’s take a look at what has kept the team busy.
ReSharper C++ 2017.1
Major areas of improvements include:


Visual Studio 2017 support

Visual Studio 2017 has launched, bringing a lot of new features and improvements to C++ developers. ReSharper C++ 2017.1 has full support for the latest Visual Studio release, including:

  • The handling of the v141 toolset, the C++ Language Standard project property and the equivalent /std compiler command line argument.
  • Understanding of several new C++ language features.
  • Support for the Enable Faster Project Load IDE option.

Most importantly, ReSharper C++ introduces initial support for the Open Folder functionality and CMake-based projects in Visual Studio 2017. The latter is particularly helpful since it eliminates the need to regenerate and reload the Visual Studio project when CMakeLists.txt is modified. However, there are a couple of related caveats:

  • In the Open Folder mode without a CppProperties.json configuration file present, ReSharper C++ will use include paths set via the INCLUDE environment variable. You can start Visual Studio from the developer command prompt to have INCLUDE automatically populated with paths to the standard library and Windows SDK.
  • Since there is no Debugging property page, additional configuration is required if you want to use ReSharper’s unit testing capabilities. You can specify how to run tests on the new page, Tools | Unit Testing | C++ Tests, in ReSharper options.

Please note that support for this kind of projects is still experimental — do let us know if you experience any problems!

We’ve also updated ReSharper C++ to handle several new types of projects — properties like predefined macros, include paths, and others should be correctly read from VisualGDB MSBuild, Linux Makefile, and CUDA projects. Moreover, when a compiler other than MSVC is used, ReSharper C++ predefines a number of macros for better compatibility with GCC and CLang compilers.

Language features

C++17 nested namespace definitions are now supported in ReSharper C++. Available since VS 2015 Update 3, this feature provides a concise way of defining nested namespaces. When ReSharper C++ detects that the latest language standard is being used, the Convert to nested namespace definition context action is available to change the old-style syntax into the new one:
Nested namespaces

ReSharper C++ also understands some of the other language features introduced in VS2017, in particular C++17 terse static_assert and C++14 no implicit const specifier on constexpr functions.

Last, std::is_constructible, std::is_convertible, std::is_polymorphic, and std::is_standard_layout C++11 type traits are now supported.

Introduce/Inline typedef

A couple of new refactorings were implemented to complement the existing Substitute typedef context action. The Introduce typedef refactoring allows you to quickly create a typedef for the selected data type and replace this data type and all its occurrences with the newly created typedef. The Inline typedef refactoring does the opposite: it replaces an existing typedef with the actual data type.
Typedef refactorings

Needless to say, these refactorings also support C++11 type aliases. If you want the Introduce typedef refactoring to insert a type alias instead of a typedef declaration, set this behavior on the options page Code Editing | C++ | Code style.

Unit testing

In addition to Google Test and Boost Test, ReSharper C++ 2016.3 delivered first class support for Catch, a cross-platform test framework for C++. Catch is popular because of its ease of use and expressive API, which allows you to divide test cases into sections (each of which is run in isolation) and structure them using BDD style. The framework is distributed as a single header file, with no external dependencies (beyond the C++03 standard library). You can always get the latest version of this header directly at this URL. For an introduction to Catch, please refer to the Catch tutorial, watch the CppCon presentation, or read the article in the CLion blog.

We are also happy to say that the author of Catch, Phil Nash, joined JetBrains as a developer advocate last fall. If you have any ideas on how to improve Catch integration into JetBrains products or have feature suggestions for Catch itself, do not hesitate to contact him!

Other updates in unit testing support include:

  • Boost Test runner has been updated to support Boost 1.62, 1.63 and 1.64. We have also fixed performance issues while working with a large number of dynamic tests and changed the runner to ignore output from the test program, so it does not affect parsing of the XML test report.
  • Google Test runner now supports the 1.8 release of the framework. ReSharper C++ will also correctly merge results of several runs and calculate total execution time if the --gtest_repeat flag is used to run the tests several times.
  • The list of unit tests is now automatically updated after external file changes (for example, when unit tests are generated as a result of a build step).

Completion

Postfix templates, a popular feature first introduced by ReSharper for C#, allow you to focus on your data rather than the syntax. ReSharper C++ gets a set of its own templates specifically tailored for C++. You can now quickly wrap an expression with several available templates, including if, else, while, do, return, switch, foreach, and others.
Foreach template

The new options page Code Editing | Postfix Templates lists all the available postfix templates. It allows you to disable the ones you do not use, and contains a number of related options.

Postfix templates

One common C++ coding practice is to prefer non-member non-friend functions to member functions. This is a great way to increase encapsulation and keep class interfaces as minimal as possible (see item 32 in Scott Meyer’s “Effective C++” for a detailed discussion). However, from the tooling perspective there have always been drawbacks to this practice. Whereas member completion list shows all the available member functions, it’s not so easy to list and complete non-member functions which are applicable to an object of the given class. This problem is now solved by ReSharper C++: when you type a dot (.) or an arrow (->) after an expression, free functions that accept that expression as the first parameter will be suggested in the completion list as well as member functions.
FreeFunctionCompletion

Code cleanup and inspections

ReSharper C++ 2017.1 introduces cleanup tasks, including:

  • A set of tasks to apply the existing quick-fixes for common code issues.
  • The Update file header cleanup task, which updates the comment at the top of the file according to the template specified on the options page Code Editing | File Header Text (take a look at the related blog post for more details).

To run code cleanup, use the command ReSharper | Edit | Cleanup Code (Ctrl+E, C) — it will work either with the current text selection, the entire file opened in the text editor, or on a set of files and projects selected in the solution explorer. You have the choice to use the built-in profile (which has several of the tasks that you might not always want to run disabled) or create your own. Here’s one that shows all the available C++ cleanup tasks:
Code cleanup

Control flow inspections (uninitialized/reassigned/unused variable and the like) used to work only with local variables and function parameters, but now class fields are also analyzed. For example, ReSharper C++ will find a self-initialization error in this snippet:
Self initialization
Or an uninitialized member here:
Uninitialized member

If you declare a local variable and initialize it later without any conditions, ReSharper C++ now suggests to join declaration and assignment where the variable is first initialized. This removes the unnecessary statement and improves code readability.
Join declaration and assignment

We have introduced several ReSharper-specific C++11 attributes that can be used to improve the results of certain inspections. For example, ReSharper C++ now understands the [[rscpp::format]] attribute (or, alternatively, [[gnu::format]]), which can be used to enable printf format string analyses for user-defined functions (RSCPP-15890).
printf attribute
There are also attributes to mark functions as having side effects (see RSCPP-18615) and guard classes for which the Unused variable highlighting should be suppressed (RSCPP-18764) — please refer to the corresponding issues for examples of their usage.

A number of smaller new code inspections were also added:

  • Incrementing expression of type bool and Deprecated register storage class specifier for language features removed in C++17.
    Incrementing bool
  • Deleting a void pointer is undefined behavior according to the C++ standard.
    Deleting a void pointer
  • Redundant void argument list (void argument lists are only useful in C code).
    Redundant void argument list
  • Private special member function is not implemented, which reminds you to use the C++11 = delete specifier instead of making the function private and omitting its definition to prohibit its usage.
    Private special member function not implemented

ReSharper’s File Status Indicator (the small icon at the top of the Error Stripe) receives a new context menu. With a right-click on the icon, you can quickly toggle not only ReSharper code analysis, but also identifier highlightings and Visual Studio code analysis (the lightbulb and squiggles). If there are code issues in the current file, you’ll also see commands for navigating between issues of the highest severity level (you can still use the good old Inspect | Next/Previous Error/Warning commands to do that).
File status menu

Finally, a new option on the options page Code Editing | C++ | Inspections controls the visibility of gutter icons (like “Navigate to definition/declaration”), should you find they clutter the user interface too much for your liking.

Documentation support

ReSharper C++ 2016.3 finally learned to display rich syntax-highlighted tooltips for C++ code elements. The contents of the tooltips mirror what was previously available through the Quick Documentation popup, namely function and variable types, containing namespace, template and function parameters, as well as documentation comments.
Quick info

In addition to the standard Doxygen syntax, ReSharper C++ now understands C#-style XML documentation comments.
XML documentation

Finally, while only references to function parameters were resolved before from inside documentation comments, now template parameter references are also supported. This means that they will be shown in the list of results from Find Usages and updated by Rename when it is used on a template parameter.

Command line tools

ReSharper Command Line Tools (CLT) are a standalone set of command line tools that enable you to run code inspections outside of Visual Studio (for example, on your CI server or code quality management system). You can now use inspectcode.x86.exe from the CLT distribution to analyze C++ projects and generate a report with found code issues. What’s the best part? CLT are free and do not require an active license. To analyze your solution, just run inspectcode.x86.exe -o=report.xml YourSolution.sln.

Command line tools

You can either get CLT via a NuGet package or download a standalone archive. In the latter case ensure that the downloaded .zip file is “unblocked” before extracting: right click on the file, select Properties and click Unblock. (Failure to do this will cause the .NET framework to load the application in partial trust, which means it won’t load or run correctly.)

For an in-depth description of CLT usage, refer to the blog post ReSharper Code Analysis Goes Beyond Visual Studio.

Performance

In terms of performance, we have recently targeted ReSharper C++’s memory usage to make it work better with huge solutions. (Since we still run in-process, we’re limited by the amount of memory Visual Studio can use as a 32-bit process.) As a result, both the memory footprint after indexing and memory traffic during indexing have improved significantly. In some cases (like the Unreal Engine 4 solution), the amount of managed memory used has decreased by up to 30%. Furthermore, a number of issues have been resolved that had caused excessive memory usage due to background editor and Find Results tabs. All of these changes should help with the debugging experience, since additional memory usage during debugging might have led to memory pressure. If you had problems with debugging before, we would also recommend trying Visual Studio 2017, which improves memory usage during debugging.

In C++ code, when you change preprocessor directives in a header file anything can happen. For example, if you add a #define or #include some file into a header file, the meaning of code can change in any file that uses that header. ReSharper C++ used to reindex all includers after a change like this, which is quite taxing on big projects, especially for common headers which get included into most C++ files. We have revisited this behavior, and now ReSharper C++ does not reindex these files by default, so the symbols in them are still used for navigation and refactoring purposes. This is a compromise between correctness and speed, the old behavior can be restored using an option in the Code Editing | C++ | Performance page. This page also contains a new option to limit the number of concurrent threads used by C++ caches — you can try tuning it to improve responsiveness during the code indexing phase, at the cost of total indexing time.

If ReSharper’s performance is still unsatisfactory, you can use the Third-party code options page to stop ReSharper C++ from indexing specific files and folders.
Third-party code
This page allows you to specify two kinds of filters:

  • Skipped Code contains files that do not get indexed at all, and is usually the right way to exclude third-party dependencies. Only indexing roots (normally .cpp files) are excluded, so if a .cpp file that is indexed includes some header files, their contents will be indexed regardless of third-party settings (since this is a prerequisite for correct parsing). So in practice, you should be able to just add the directories with third-party libraries to “Skipped code”, and if you include a header from a skipped library into your code, ReSharper will still be able to navigate to it.
  • Library Code contains files that ReSharper C++ must not modify. Highlightings are disabled inside these files, but they get indexed and ReSharper C++ is aware of symbols inside them. For example, Goto Symbol and auto-import will work for those files.

The File and folders list can only contain files and folders that are a part of the solution. The File masks list allows to match arbitrary paths. Masks are automatically prefixed by **/ and are matched against absolute file paths. If you want to match all files inside a folder, /** would also be required at the end of the mask. So for example, files inside C:/Foo/Bar would be matched by Bar/**, Foo/Bar/**, or C:/Foo/Bar/** (although shorter masks might match unwanted folders too).

Code formatting

EditorConfig offers a convenient way to share code style settings between teammates who use different editors and IDEs. ReSharper 2017.1 supports EditorConfig configuration files out of the box. To learn more about this, refer to the Using EditorConfig help section or watch the introductory video.

A new setting in the General Formatter Style options page (turned off by default) makes ReSharper C++ automatically detect and set the indent size used in a file. This feature becomes particularly handy in solutions where different files have variable indent sizes.

Indenting of preprocessor directives is now supported and controlled via the Indentation | Preprocessor directives indenting formatter option. Code that uses the OpenMP API is one example where this option is crucial for correct formatting:
Directives indenting

The list of other formatter options introduced for improved configurability includes:

  • Indent namespace members.
  • Break line in simple case statement.
  • Spaces within/after parentheses in cast expressions.
  • Place enumerators on new line.
  • Align multiline chained method calls and binary operators.

The list of small and not-so-small improvements in navigation and find usages includes:

  • The Find Results window now works asynchronously, meaning that you can work with the results tree while usage search is still in progress.
  • The Go to Everything and Go to Text popups support inline commands for advanced filtering of search results.
    Search filters
  • The Find Results window allows you to group results by kind of usage. This ability is very useful if you want to inspect only specific usage scenarios.
    Find results grouping
  • Recent Files can delete entries with the Delete key, and both the Recent Files and Recent Edits popups will now show the path of the file, to avoid confusion with similarly named files.
  • There is a new setting to remember the last search in Go to Everything, Go to Text and other search actions.
  • ReSharper’s Search & Navigation page adds a new option to open files in the preview tab from everywhere. This option is turned off by default.

ACCU 2017

The ACCU 2017 conference takes place in Bristol April 25-29 and as always has a great lineup of presenters and a lot of interesting talks, including “Functional C++ For Fun And Profit” and “A look at C++ through the glasses of a language tool” by our very own Phil Nash and Anastasia Kazakova. You can watch video recording on the ACCU conference YouTube channel later if you do not attend, but if you do, be sure to stop by the JetBrains booth to say “Hi,” grab a couple of souvenirs or shoot any questions at members of the ReSharper C++ and CLion teams.

That about wraps it up! All in all, 210+ issues have been fixed in the 2016.3 release iteration, and 140+ issues in 2017.1. We’d like to give a big shout-out to everybody who tried Early Access Preview (EAP) ReSharper builds and helped us iron out the bugs and improve the product. As always, please leave us any feedback and report issues either in the issue tracker or on the support forum. Develop with pleasure with ReSharper C++!


Download ReSharper C++ 2017.1

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 *