ReSharper 2016.1 Help

Code Inspection and Quick-Fixes in C++

The key features of ReSharper's code analysis are also supported in C++. You can find the detailed information on these features in the corresponding topics of the Code Analysis section. In the main topic of the section, you can also find the feature matrix and check what exactly is supported in C++.

In this topic, you can find some examples of using code analysis features in C++:

Code Inspection

ReSharper's static code analysis detects most of compiler errors and some compiler warnings in C++ files.

Besides, it finds other code issues, which otherwise would be found in runtime. For example, using a virtual method in constructor leads to unexpected behavior as mentioned in this StackOverflow question. ReSharper points at this problem before you even compile:

ReSharper warning. virtual method in constructor

The analysis is performed by applying code inspections to the current document or in any specified scope.

Code inspection results in a C++ project

To learn how to customize code inspection, see Configuring Code Inspection Settings.

Quick-fixes

Quick-fixes let you automatically resolve most of code issues found with code inspection. If one or more quick-fixes are available for a code issue, you will see the corresponding action indicator when your caret is on the highlighted code. Press Alt+Enter to see and apply the desired fix.

ReSharper provides over 50 quick-fixes for C++. Here are some examples:

Create from usage

If you use an undeclared symbol, ReSharper suggests one or more quick-fixes for creating the symbol based on the usage:

Generating C++ field from usage

Create declaration

If a member function in a C++ file does not have declaration in the header file, ReSharper helps you create the missing declaration according to the signature of the implementation:

Generating declaration for C++ class member

Add missing #include directive

if you use a type that is defined in the standard libraries or elsewhere in your project, ReSharper helps you add the missing #include directives automatically:

ReSharper helps adding missing includes automatically

Remove unused #include directives

All unused #include are highlighted and can be easily removed with a quick-fix:

Removing unused #include directives

Initialize variable

ReSharper detects uninitialized variables and helps initializing them with the default value:

ReSharper helps initialize variables in C++

Replace the dot (.) with arrow (->) and vice versa

If the dot(.) operator is erroneously applied to a pointer, ReSharper helps you replace it with the arrow (->) operator:

ReSharper helps replacing the dot operator with arrow

The reverse quick-fix is also available:

ReSharper helps replacing the arrow operator with the dot

Change variable type

If the specified type of a variable or a field does not match to the assigned value, ReSharper provides a quick-fix to use the correct type in the declaration:

ReSharper helps fixing types of variables and fields

Change return type

If a function return type does not match the value it actually returns, ReSharper lets you quickly fix the return type:

ReSharper helps fixing types of variables and fields

See Also

Last modified: 19 August 2016