cpp:S835 false positive

  • What language is this for?
  • Which rule?
  • Why do you believe it’s a false-positive/false-negative?
    A C++20 designated-initializer clause can be a an initializer-clause (with = in front) or a braced-init-list. For a braced-init-list, I see no reason why additional braces should be required. In fact, an additional set of braces would not even compile (at least with MSVC).
  • 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 X
    int y;
// SonarQube reports code smell "cpp:S835 braces around scalar initializer"
X x{.y{3}};
// Compiler reports "error C2440: 'initializing': cannot convert from 'initializer list' to 'int'"
X x2{.y{{3}}};


Hey there.

Thanks for the report. We’re already tracking this false-positive here.

Oh, sorry! Somehow the search function didn’t bring it up and it was so long ago that I already forgot that I reported it :sweat_smile:

1 Like

Not a glowing review of our reactivity, but thanks :pray: better reported twice than never.