False positive on cpp:S3230 in move constructors


SonarLint SonarSource
Clion 2021.1.3
Ubuntu 20.04.3 LTS
False positive on code, where move constructor assigns values to fields of the source object. In this case initialization list can’t be used to modify the source object. The rule should only be triggered if fields of the current object are assigned in the constructor, not when fields of other instances of the same type.

class Resource
  Resource() = default;

  Resource(Resource&& source) noexcept : resourceId(source.resourceId)
    source.isResourceOwned = false;  // false positive of cpp:S3230

    if (isResourceOwned)

  int resourceId = acquireResource();
  bool isResourceOwned = true;

  static int acquireResource()
    return 1;  // pretend this method allocates some resource and returns some id for it

  static void releaseResource(int)
    // pretend this method releases some resource

Hello @shojtsy,

Good catch, it is an obvious false-positive. Ticket created.


1 Like

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