cpp:S3584: False positive when using placement new

cpp:S3584 detects a potential memory leak in the following example code, but the following minimal example does not use any dynamic memory and can’t leak memory, because it uses placement new:

#include <new>

struct MyStruct { int x; };

int main() {
    char buffer[sizeof(MyStruct)];
    MyStruct* p = new (buffer) MyStruct();  // cpp:S3584 False positive detected here.
}

SonarQube for IDE version = 4.17.0, but this also happens in SonarQube Server.

Hello @daulis,

Thanks for reaching out.
I’m not able to reproduce the issue with the code you shared. Could you create a reproducer so we can investigate any environment/setup related issues?

To generate the reproducer file when using SonarQube Server:

  • Search in the analysis log for the full path of the source file for which you want to create a reproducer (for instance, a file that contains a false-positive). You will have to use exactly this name (same case, / or \…)
  • Add the reproducer option to the scanner configuration:
    sonar.cfamily.reproducer=“Full path to the source file”
  • Re-run the scanner to generate a file named sonar-cfamily-reproducer.zip in the project folder.
  • Please share this file. If you think this file contains private information, let us know, and we’ll send you a private message that will allow you to send it privately.

Thanks