Early Access Program

ReSharper C++ 2023.3 EAP: Clang 17, Updated Attributes

The new Early Access Program build is here with the upgraded bundled clang-format and clang-tidy binaries, a new action to Generate destructor, support for various clang intrinsics, and other updates. Read on for more details and check out the full list of issues we’ve fixed in this update.

You can download the free EAP builds from our website or via the Toolbox App.


Working with attributes

If you ever need to check whether some specific attribute is available in the current standard or compiler version, C++20’s feature testing is here to save the day. Using __has_cpp_attribute(operand) in preprocessor conditions, you can test whether the attribute referenced by its operand is recognized by the compiler. ReSharper C++ now correctly handles __has_cpp_attribute to better support attribute annotations in C++ standard libraries:
Besides support for the standard attributes, we also have several ReSharper-specific attributes:

  • [[jetbrains::format]] can be used to enable format inspections for custom printf-like functions and works similarly to [[gnu::format]].
  • [[jetbrains::guard]] can be used to suppress the Local variable is never used inspection. Mark a class with this attribute to let ReSharper know that the class performs important work in its constructor.
  • [[jetbrains::has_side_effects]] can be used to mark operator= as having side effects to suppress the Assigned value is never used inspection.

You may have seen these attributes before with an [[rscpp::...]] prefix, and now both the old rscpp and the more unified jetbrains versions are accepted.

In this EAP build, we’ve added a new [[jetbrains::pass_by_value]] attribute to suppress the Pass value by const reference inspection. Why use the suppressing attributes instead of disabling the inspection with a comment? When you don’t want to see a warning for a specific class or struct, you can always select Inspection:… | Disable once with a comment from the Alt+Enter menu to add a comment suppressing the inspection on the current line or in a file. You’ll then have to add the suppressing comment for all class usages as well. In these cases, it’s much easier to specify a suppressing attribute in a class declaration once.

If you need to apply a ReSharper attribute to a library class from an external library, you can use the attribute on a forward class declaration instead: class [[jetbrains::pass_by_value]] irc_message;.

Additionally, if your compiler shows a warning about an unknown attribute, you can guard the declaration with the __JETBRAINS_IDE__ or __RESHARPER__ macro:

We’ve also tuned the mentioned Pass value by const reference inspection to ignore types marked with __declspec(intrin_type) like various standard SSE types.

Coding assistance

The Alt+Insert Generate menu helps you quickly create standard code constructs. In this EAP build, we’ve added a new action to the list allowing you to generate a destructor:

Generate destructor

When invoked in a polymorphic class, the action will make the generated destructor virtual. If there is already a virtual destructor in one of the base classes, the action will use the Specifiers to use on overriding destructors syntax style to insert the corresponding override and/or virtual specifiers. You can configure the function body style that Generate destructor uses on the Code Editing | C++ | Code Generation options page.

The new Generate inline definitions action lets you quickly generate bodies for several functions at the same time. Similar to the existing Generate definitions, the new action is available on the name of a class or when several function declarations are selected in the editor.
Generate inline definitions

When you invoke the Introduce variable or Introduce field refactorings on a nested expression, ReSharper C++ now lets you choose the target expression explicitly instead of automatically using the outermost exception:

Code analysis

We’ve upgraded the bundled clang-format and clang-tidy binaries to Clang 17, bringing updates from the latest LLVM release.
clang-tidy 17

Some clang-tidy checks output more details in addition to the warning text. ReSharper C++ now shows these additional notes in the tooltips:
Additional notes from clang-tidy

We’ve introduced support for the pack pragma used with the __pragma keyword. The __pragma (pack) syntax is sometimes used inside macro definitions, since it’s not possible to use #pragma directives inside a macro definition. In cases like this, ReSharper C++ now correctly computes the sizes of packed structures, so you can rely on analysis and highlighting for static assertions.
__pragma (pack)

A new inspection provides a set of warnings and errors for cases where a character literal contains multiple characters. This is conditionally supported only for regular and wide character literals, and even then the behavior is implementation-defined.
Multi-character literal

Among other notable improvements, we’ve introduced support for various clang intrinsics such as __is_const(), __is_member_pointer(), etc.

There are also a few new formatting settings:

  • Break line before -> in trailing return types.
  • Break line after -> in trailing return types.
  • Spaces within empty blocks.

Those are the highlights of this EAP build! If you encounter any issues, don’t hesitate to report them to our issue tracker.


Your ReSharper C++ team
The Drive to Develop

image description