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