S835 false-positive with an array inside the structure

I believe we have encountered a false-positive for rule S835 when brace-initialising a structure which has a field which is an array.

In the following code:

#include <cstdint>

struct Test1 {
    uint16_t field1;
    uint8_t field2[64];

void test() {
    [[maybe_unused]] Test1 t1{ 0, {0} };

SoarQube raises S835 against the initialiser of the member field2 with recommendation “Correct this initialiser to initialise all elements”.

  • What language is this for?
    C++ (11)

  • Which rule?

  • Why do you believe it’s a false-positive/false-negative?
    In the example C++ code linked below, the structure is fully initialised in accordance with the language specification for the used braced initialiser syntax (the generated assembly code confirms this). Regardless, S835 is flagged for the array member.

  • Are you using
    Found on SonarQube 9.4 but reproduces on godbolt.org

  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
    The issue is reproduced on godbolt.org here.

1 Like

Hi @m2427,

thank you for reporting this. I agree that this is a false positive. I’ve created [CPP-4897] - Jira to track this issue.


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