Step Filters in ReSharper C++

It hasn’t been long since the first debugging-assistance features — inline values, searchable DataTips, and breakpoints navigation — appeared in ReSharper, but today we’re happy to present yet another cool feature — step filters in C++.

Why do you need step filters? Well, the illustration below explains pretty much everything:

ReSharper step filters

Some functions never need to be stepped into because they are either very simple or very well tested. But the problem is that the debugger cannot tell which functions are worth debugging and which aren’t, and therefore Step Into will not miss any user function on its way.
Visual Studio’s Just My Code functionality takes basic care of this problem by ignoring non-user code and letting you customize ignored symbols using text config files.

However with ReSharper C++, you can now visually maintain step filters — a list of function masks that tells the debugger what should be skipped on stepping. By default, this list includes a lot of library functions and it can be extended.

Of course, ReSharper wouldn’t be ReSharper without having some handy goodies here: to quickly add a function to the filters, you can press Alt+Enter on that function while debugging and pick the corresponding action:

A context action that adds a ReSharper step filter

The filters are stored using ReSharper’s layered settings. By default, the action saves the filter in the ‘Solution personal’ layer, but you can use the action’s submenu to choose where the filter should be saved — e.g in the ‘Solution team-shared’ layer, so that this filter will be also available to your teammates.

You can study and further configure step filters on the Tools | Debugging | C++ options page:

ReSharper C++: step filter options

As always, your feedback regarding this feature is most welcome, and you can try it right now in the latest build of ReSharper 2018.1 EAP.

Posted in ReSharper C++ Tips & Tricks | Tagged , , | 2 Comments

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

Posted in ReSharper C++ Tips & Tricks | Tagged , , | Leave a comment

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:
add_typename

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

Posted in ReSharper C++ Tips & Tricks | Tagged , , | Leave a comment

C++ Annotated: Apr – Aug 2017

Today we are happy to share our next compilation of C++ news with you.

Subscribe to the regular C++ Annotated and be the first to get the next edition!

C++ Annotated: April – August 2017

A long time has passed since the last edition of C++ Annotated. Which means today we have lots of great articles and news to share with you. In this edition:

  • C++ language news
    • C++20
    • Metaclasses
  • Conferences
    • Recent events like ACCU and C++Now
    • Upcoming events
  • Learning
  • Releases

C++ language news

C++20

wg21-timeline-2017-07b
With C++17 ready for final publication by the end of 2017, we can now start thinking about the future of C++ and in particular C++20. The Toronto C++ committee meeting was solely about just this! Just look:

  • Concept TS was merged into C++20 draft. It takes now only one clean syntax (out of three) and doesn’t include function concepts.
  • Coroutines TS, Networking TS and Ranges TS are done, Modules TS is quite close.
  • Several nice enhancements like designated Initializers, template syntax for generic lambdas, default member initializers for bit-fields and others.

It seems that Fall will bring even more exciting features to C++20, and maybe for example, compile-time reflection. (And here’s one to definitely have a check of the talk by Jackie Kay from C++Now). And not to mention the library evolution group and new standard library under discussion. To find out more check Herb Sutter’s traditional trip report. And if you want a summary table view, check the trip report by Botond Ballo.
Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

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

Posted in ReSharper C++ Tips & Tricks | Tagged , , , , | Leave a comment

C++ Annotated: Jan – Mar 2017

Today we are happy to share our next compilation of C++ news with you.

Subscribe to the regular C++ Annotated and be the first to get the next edition!

C++ Annotated: January – March 2017

In this edition:

C++ in 2017

The C++ ecosystem

logo-sunThis blog post about the C++ ecosystem in 2017 is worth a special mention. Written in January, it overviews nicely the main expectations and trends, and not just about the language. While C++17 is indeed the main topic for this year’s discussions (as well as the features that failed to be included and so postponed for the future), it is also about adopting new standards and libraries, and of course the community including user groups and conferences.

C++17

cpp_17As C++17 is approved, pending national body comments, there are lots of resources now where you can find the final feature list, explanatory code samples, committee meeting live threads and committee meeting trip reports. This list by Bartlomiej Filipek is quite useful as it provides code samples for each feature, lists the key compilers (GCC, Clang, MSVC) explaining the versions where the feature is supported, and links to various additional articles. It’s very detailed and includes every small change.
Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

C++ annotated: Sep – Dec 2016

Today we are happy to share our next compilation of C++ news with you.

Subscribe to the regular C++ Annotated and be the first to get the next edition!

C++ Annotated: September – December 2016

In this edition:

Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

Introducing Phil Nash, Developer Advocate for C++, Objective-C and Swift tools

Phil NashPhil Nash has joined us recently as a Developer Advocate for C++, Objective-C and Swift tools. Here we talk to Phil about his experience and interests and introduce him to all of you.

Twitter: @phil_nash
Blog: levelofindirection
GitHub: philsquared

A: Hi Phil, and welcome to the JetBrains team! Let’s talk about you. Can you please share a bit about yourself?

P: Hi Anastasia. Thanks for having me here. A bit about me? Well, I’ve been programming since I was 9. Like most who came of programming age in the early 80s, I started with various versions of BASIC on 8-bit home computers (ZX-81, ZX-Spectrum, Commodore-64, BBC Micro and others), but within a few years progressed on to assembler (mostly 6502 – but later 68000 on the Amiga, then 8086 on PC). In the early 90s I went for my first programming job, writing C & C++, which I prepared for by reading a book on C the night before. Somehow I managed to bluff my way in – but I hadn’t been there long before I realized I knew more C++ than anyone still there. That was the start of my C++ journey. It started on MS-DOS, but as the 90s progressed I naturally fell into Windows – which I did exclusively for the rest of the 90s.

A: What’s your background as a developer? I know you did C++ on Windows for a very long time. How did you end up doing iOS development in Objective-C and now Swift?

P: In the 2000s I changed things up a bit. The signs were there that C++’s heyday was coming to an end and I thought I should either learn other languages, or see which industries C++ would remain strong in. I started with the latter and moved into embedded programming – specifically mobile comms – where I stayed for about five years. It was a good experience and I’m glad I did it, but I also learned that embedded-programming was not for me. So I branched into banking, where I’ve mostly stayed until now. During that time, though, I also moved on the “other languages” front. First C#, then Python, then D and F#. At home I’d switched over exclusively to Macs, so I was interested in learning Objective-C, but it wasn’t until the iPhone AppStore launched that I gathered sufficient motivation to get past the initially steep learning curve!
Continue reading

Posted in Uncategorized | Tagged | 1 Comment

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!

Posted in ReSharper C++ Tips & Tricks | Tagged , , | 3 Comments

C++ Annotated: Jun – Aug 2016

Today we are happy to share our next compilation of C++ news with you.

Subscribe to the regular C++ Annotated and be the first to get the next edition!

C++ Annotated: June – August 2016

In this edition:

  • Interviews
  • Conferences
  • News & Stories
  • Releases

Interviews

Jon Kalb speaks about CppCon, C++17 standard and C++ community

jon-kalb

These months were quiet in terms of conferences, but September is just around the corner with the most well-known and significant event in the C++ world – CppCon. CLion’s PMM, Anastasia Kazakova, talked to Jon Kalb, CppCon Chair and C++ instructor. The first topic discussed was the C++ community and how modern language features are adopted by it. They went on talking about Jon’s feeling towards C++17 and his strong faith that the committee did everything just right. Jon also shared a secret recipe and a magic ingredient of CppCon success and a story of CppCat, and spoke about the era of tools for C++.

An interview with Sean Parent

sean-parent

Jens Wellers from Meeting C++ did an interview with Sean Parent. Learn why Sean would select Argument-Dependant Lookup if he could remove one feature from C++ language; why he thinks garbage collection has no place as a part of the general allocation scheme; discover his views on functional programming, smart pointers, coding guidelines and a bunch of other topics.

Stephen Kelly at CppCast

stephen-kelly

During these months many interesting episodes of CppCast were published. One of them is an interview with Stephen Kelly, Qt and CMake expert and maintainer. He talks about Qt build system and CMake similarities and how they can co-exist. While the most interesting part of the interview is dedicated to CMake API and how tools like IDEs can use it to integrate deeper with CMake, Stephen also answers questions about its design and why they dropped the idea of simply generating more content on a CMake call and decided to use the idea of the CMake server instead. In the end, Stephen shares some tips on CMake productive usage, like creating and using CMake config files.

Another great episode of CppCast worthy of a mention is an episode with Herb Sutter reviewing the results of the Oulu C++ committee meeting.
Continue reading

Posted in Uncategorized | Tagged , | Leave a comment