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?
S835 -
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.