The following code yields cpp:S3230:
#include <napi.h>
template <class T, typename P>
class CommonAwaitWorker : public T
{
public:
explicit CommonAwaitWorker(const P &p)
: T(p), deferred(T::Env()) {} // Do not use the constructor's initializer list for data member "deferred". Use the in-class initializer instead. sonarlint(cpp:S3230)
private:
const Napi::Promise::Deferred deferred;
};
class AwaitWorker : public CommonAwaitWorker<Napi::AsyncWorker, Napi::Env>
{
public:
using CommonAwaitWorker::CommonAwaitWorker;
};
class AwaitWorkerWithProgress : public CommonAwaitWorker<Napi::AsyncProgressWorker<float>, Napi::Function>
{
public:
using CommonAwaitWorker::CommonAwaitWorker;
};
(Implementation details omitted.)
Napi::Promise::Deferred()
is initialized either with Napi::AsyncWorker::Env()
or with Napi::AsyncProgressWorker<float>::Env()
.
Replacing T
with a concrete class does not yield cpp:S3230:
class AwaitWorker : public Napi::AsyncWorker
{
public:
explicit AwaitWorker(const Napi::Env &p)
: Napi::AsyncWorker(p), deferred(Napi::AsyncWorker::Env()) {}
private:
const Napi::Promise::Deferred deferred;
};
So I am assuming class T
is confusing the rule checker somehow, and this is a false positive.