ReSharper C++ 2021.2 EAP: Inline Function Refactoring, Modernizing Inspections, Faster Clang-Tidy
We are moving into the next stage of this EAP cycle with a new set of features and fixes. Today’s EAP build comes with:
- Inline Function refactoring.
- New modernizing inspections: std::size can be used and Zero initialization can be used instead of memset.
- Faster Clang-Tidy analysis for files with a lot of included code.
Starting from this EAP build, you can join the program only if you have an active JetBrains account. If you have already logged in, you can access the EAP builds automatically. If you have not yet logged in, you will be redirected to this page, where you can enter your credentials or create a new JetBrains account. You can learn more in this blog post.
Inline Function refactoring
With ReSharper C++, you can use the Extract Method refactoring to create a new method based on the selected code fragment. Before 2021.2 this only worked in one direction, but now you can use the opposite code transformation – the new Inline Function refactoring!
The Inline Function refactoring is usually used when the function body is quite obvious, so code will become more straightforward if you minimize the number of extra function calls. To invoke it, place the caret on the function call and select Inline Function from the Refactor This menu, or choose ReSharper | Refactor | Inline from the main menu.
If the refactoring is applicable, ReSharper C++ will perform the necessary transformations, handle all name conflicts for used variables, and reformat the resulting code. Otherwise, there will be a short pop-up message explaining why it’s not a good idea to try inlining some method.
Please give it a try and let us know if there is anything we should adjust. Your feedback is always welcome!
We’ve added two new inspections that help you modernize your code:
- std::size can be used. The C idiom for array size calculation is error-prone and works incorrectly when the
sizeofoperator is applied to a pointer instead of a built-in array. This happens, for example, with decaying function parameters (
void f(int arr)) or dynamically allocated arrays (
int arr). The new inspection suggests using
std::sizeas a type safe alternative.
- Zero initialization can be used instead of memset. The accompanying quick-fix replaces
memsetwith a modern zero-initialization to shorten expressions and prevent various
memsetrelated errors like underflows while filling in an object of the wrong size.
Faster Clang-Tidy analysis
We’ve improved the performance of the bundled Clang-Tidy. You might have noticed a message about some long-running analyses still working in the background on files with a lot of included code, particularly in C++20 projects:
Code analysis now finishes up to several times faster on such files.
That’s all the news for now. As usual, the EAP build is free to use and available for download from our website or via the Toolbox App.
Your ReSharper C++ team
The Drive to Develop