Replace the use of void in an inheritted method override

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for?

C++

  • Which rule?

cpp:S5008 Tags: based-on-misra cppcoreguidelines

The line reads:

Snippet

__declspec(nothrow) HRESULT __stdcall efxc2CompilerIncludes::CompilerIncludes::Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes) {

  • Why do you believe it’s a false-positive/false-negative?

This is an overridden method as indicated by the header for that file and that header says:

Snippet

__declspec(nothrow) HRESULT __stdcall Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes) override;

  • Are you using

    • SonarCloud?

It did appear in SonarCloud and I marked it as “Acceptable for now” since I could not compile if I changed the LPVOID type.

  • SonarQube - which version?

N/A

  • SonarLint - which IDE/version?

SonarLint for Visual Studio 2022.

* in connected mode with SonarQube or SonarCloud?
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

Hi @jpmugaas, and thanks for taking the time to share the feedback with us,

Just to make sure I understand the false positive you are describing. Could you confirm that the following example demonstrates it?

struct Base {
  virtual ~Base() = default;
  virtual void f(void* ptr);
};

struct Derived : Base {
  void f(void* ptr) override;
};

void Derived::f(void* ptr) {  // S5008 reported here, FP?
    // ...
}

You can also check the behavior of the analyzer on this example on Compiler Explorer.

Yes, it triggers the same behavior. The problem was that I was inheriting from an interface provided by the Win32 API so I can’t easily change void* to something else. The API is ID3DInclude (d3dcommon.h) - Win32 apps | Microsoft Learn .

Thank you, @jpmugaas, for sharing this feedback.

We are aware of this problem and track it under [CPP-2782] - Jira. However, please understand this is part of a larger and complex problem.

If you cannot change the header file, I think it would be acceptable to mark this issue as a False Positive.

Cheers