False positive for pointer dereference when using doctest macro

Must-share information (formatted with Markdown):

  • SonarQube Server
  • linux server on redhat 8
  • write a unit test in c++
  • write a unit test using doctest’s macro REQUIRE_MESSAGE

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

In a unit test, using the doctest library, in this block of code:

    REQUIRE_MESSAGE((pool != nullptr), "Pool is null");

    Converter converter;

    const auto a = converter.build(*pool);

Sonarqube raises this error at the call to build(*pool):
cpp:S2259 Forming reference to null pointer

It doesn’t expand the doctest macro REQUIRE_MESSAGE which checks if pool is nullptr.

Hi,

Welcome to the community and thanks for this report!

What version of SonarQube are you using?

 
Thx,
Ann

Hello Ann,

We use enterprise edition 9.9.5. There is a plan to migrate to v10 later this year

Hi,

Your version is past EOL. You should update to either the latest version or the current LTA (long-term active version) at your earliest convenience. Your update path is:

9.9.5 → 2025.1.4 → 2026.1

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

If your error persists after update, please come back to us.

 
Ann

1 Like