ReSharper C++ 2020.2 EAP: safe_cast, Misspelled Directives, and Forward Declaration
The new EAP build for ReSharper C++ 2020.2 is here! There hasn’t been much news from us for the last few builds, but don’t worry – we are working hard on a quality-targeted release that fixes bugs and performance issues, so we’ve had less time for introducing new features. But this week we’ve collected a variety of new things to share with you:
- “Use safe_cast” quick-fix for C++/CLI.
- Error highlighting for misspelled preprocessor directives.
- An import completion option adding a forward class declaration.
- Automatic cleanup on save, autosave after cleanup, and cleanup for recent files.
As usual, the EAP build is free to use and available for download from our website, or via the Toolbox App.
“Use safe_cast” quick-fix
safe_cast operator in C++/CLI is especially useful when downcasting from a base class to a derived one:
safe_cast performs a dynamic check and throws
InvalidCastException if the conversion fails. For casts to tracking handle types, a C-style cast is mapped either to a
safe_cast, or to a
safe_cast and a
const_cast. But if you follow common C++ guidelines and use only named C++ casts in your codebase, you can now use a new quick-fix to convert a C-style cast to a
safe_cast. For example, when performing a downcast with a generic type:
Misspelled preprocessor directives
ReSharper C++ now highlights spelling mistakes for preprocessor directives:
Adding a forward class declaration
If a class is not included in the current file, the completion list will suggest a new option. In addition to being able to insert an include directive, you can now add a forward declaration.
If you’re not a fan of forward declarations, you can configure the import completion behavior to always insert an include directive or show a list of choices only in header files (ReSharper | Options | Code Editing | C++ | Code Completion).
Also, the new build includes important updates from ReSharper itself. For example, code cleanup can now be launched automatically on save, and – vice versa – cleaned up code can be autosaved. Moreover, there is now an option to apply code cleanup only to the changed parts of recently modified files. You can enable these features on the Code Cleanup page of ReSharper options.
That’s all for now! The full list of fixed issues can be found in our tracker.
You’re welcome to check this build out, and please let us know what you think!
Your ReSharper C++ team
The Drive to Develop