Hello,
it seems we got a false positive on C++ rule “ Unused local variables should be removed[cpp:S1481]”.
We are using SonarQube 10.0.0.68432.
This issue is raised on this code:
if (i == 0)
{
BOOL suc = wnddata.m_pChildWnd->SetWindowPos(pLastChildWndArranged == nullptr ? &CWnd::wndTop : pLastChildWndArranged, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
ASSERT(suc == TRUE);
}
else
{
BOOL suc = wnddata.m_pChildWnd->SetWindowPos(vFldChildWnd[i - 1].m_pChildWnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
ASSERT(suc == TRUE);
}
It complains about the unused variable ‘suc’ which is actually used inside the ASSERT macro. We have a very similar issue with the _ASSERTE macro on another code - see below:
void CServiceModule::Run()
{
_Module.dwThreadID = GetCurrentThreadId();
// HRESULT hr = CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call
// instead to make the EXE free threaded.
// This means that calls come in on a random RPC thread
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
_ASSERTE(SUCCEEDED(hr));
// This provides a NULL DACL which will allow access to everyone.
CSecurityDescriptor sd;
sd.InitializeFromThreadToken();
hr = CoInitializeSecurity(sd, -1, NULL, NULL,
Value stored to 'hr' is never read
RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
_ASSERTE(SUCCEEDED(hr));
hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, REGCLS_MULTIPLEUSE);
_ASSERTE(SUCCEEDED(hr));
Here the complaint is that ‘hr’ is never read.
Thanks!