I would like to detect the following problem with unreachable code in C++/COM by using some free tools or Visual Studio 2015.
void Foo()
{
HRESULT hr = E_FAIL;
// variable hr is not changed here
// a lot of source code here so detecting this situation manually is not so easy
if (SUCCEEDED(hr))
{
printf("Message."); // unreachable code
}
}
Edited:
I have edited this question, because I have got same 'down votes', but I did not get a valuable answer. Of course in my project I set level of warning to /W4
, but this setting can recognise only simply cases like this (maybe I am wrong but hence my question):
int main()
{
return 0;
printf("Message.");
return 0;
}
When the code is more sophisticated the compiler does not warn me (notice when you write similar code in c# you get a proper warning):
int main()
{
if (false)
{
printf("Message.");
}
return 0;
}
When we create even more sophisticated example we do not get the warning in both languages - C++ and C# (my original example is even more sophisticated because uses COM macro):
int main()
{
bool someCondition = false;
if (someCondition)
{
printf("Message.");
}
return 0;
}
Maybe I was made a mistake, because I asked about tools (I thought about some addons for Visual Studio because I think this kind of functionality is not built in this IDE), but I believe exists any reasonable approach to find this bugs. My real application has about 3 millions lines of code and my goal is to find and refactor this places. Any ideas will be appreciate.