cpp:S835 false positive/strange behavior with C++20 designated initializers

  • What language is this for?
    C++

  • Which rule?
    cpp:S835

  • Why do you believe it’s a false-positive/false-negative?
    I don’t really understand the relation of the rule explanation to this piece of code, to be honest.

  • Are you using

    • SonarQube - which version?
      Enterprise Edition - Version 9.9 (build 65466)
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

struct Test1 {
    int field;
};
void test()
{
    [[maybe_unused]] Test1 t1{.field{3}};
}

Hi Philipp,

Yes, that indeed seems to be a false positive; you can mark it as such in the SonarQube and SonarCloud products. It won’t show up in subsequent analysis runs, then.

I also cannot reproduce it on godbolt.org (check the upper, right-hand side window that shows Sonar’s findings).

Cheers

Hi Philipp,

thanks for conforming. Regarding godbolt: What kind of rules are enabled there? cpp:S835 is not part of the default “Sonar Way” ruleset, AFAIK.

I just double-checked on that: godbolt uses the “Sonar Way” profile by default.

By enforcing cpp:S835 using an internal option, I can reproduce the false positive in godbolt.

I’ve created a respective ticket at SonarCFamily - Issues - Jira.

Feel free to track progress on this FP.

Cheers

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.