Why do you believe it’s a false-positive/false-negative?
Issue description says that SonarCloud does not report a warning if the result of the naked new is directly passed as a function argument, which in this case is true; it is directly passed to the shared_ptr<> constructor. Additionally, the advice to replace with make_shared does not work in this case since the constructor of the class is private.
There is an issue for this reported here, but it has no update since 2021: [CPP-3252] - Jira
Are you using
How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
template <typename... Args>
[[nodiscard]] static std::shared_ptr<Example> create(Args&&... args)
return std::shared_ptr<Example>(new Example(std::forward<Args>(args)...));
auto example = Example::create();
Thank you for reporting this issue with a nice example.
I agree the exception should apply in this case so I’ve raised a ticket to track this bug: [CPP-4508] - Jira
Regarding the private constructor, I feel there is also room for improvement in the rule description. It’s not directly obvious however how this should be done w.r.t. both rules S5025 and S5950. I’ve raised [CPP-4509] - Jira to look at this aspect.