Question regarding cpp:S3646

The SonarQube rule cpp:S3646, ‘Declare this variable in a separate statement,’ indicates that a type definition and variable declaration should not occur within the same statement. The provided non-compliant example is:

struct Container { int size; } container; // Noncompliant

However, my observations suggest a nuanced behavior. When analyzing the following code, the rule reports an issue:

struct Container { int size; } container;
Container container2; // This line seems to trigger the issue, or the combination.

Conversely, if only the first line is present

struct Container { int size; } container;

SonarQube does not flag it as non-compliant in my tests, which contradicts the rule’s example.

Could you please clarify the precise conditions under which cpp:S3646 is activated?

Hey @aidyk !

Can you tell us what version of SonarQube you’re using?

Sorry for the confusion. I’ve now confirmed that unnamed struct declarations only work without issue when immediately followed by variable declarations. I’ll close the thread; thanks anyway.