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?