Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

False positive Error 503 for call to template function

I have some code that PC-Lint is giving me Error 503: Boolean argument to relational on. It is a call to a template function which is defined like this:

template <typename ITypeToUse>
void ShowWindowEx(
    HWND hWnd,
    int nCmdShow,
    ITypeToUse *pControl);

The call itself looks like this:

ShowWindowEx<IActualType>(this->GetWndHandle(), SW_SHOW, m_spControl);

Appearantly, the part ShowWindowEx<IActualType>(...) is interpreted as Identifier1 < Identifier2 > Expression... PC-Lint seems not to be aware that ShowWindowEx is a template function which requires a type in angled brackets and tries its best to interpret it as a boolean expression.

I am aware that I can simply tell lint to ignore this error for this line (though in reality it's about 30 lines), but I'd like to prevent this from happening again. Also, as far as I know, PC-Lint should be capable of handling template function calls, any idea why this is not the case here?

The declaration is inside a class in a header and the call is in another member function of that class, which is declared right before ShowWindowEx is. The implementation of both member functions happens in the .cpp file in the same order, so the call to ShowWindowEx happens before its implementation. Is it possible PC-Lint just ignored the header?

EDIT: I now changed the function prototype to:

template <typename IPointerToUse>
void ShowWindowEx(
    HWND hWnd,
    int nCmdShow,
    IPointerToUse pControl);

So the template will take care of the type being a pointer. Thanks DeadMG for the suggestion. Question still stands, as I see no reason the above should not have worked, but it works this way as well.

like image 424
SvenS Avatar asked Nov 14 '22 17:11

SvenS


1 Answers

503 normally is a C warning, not C++. Can it be that your C++ file containing the template function call is considered a C file by Lint, maybe by using *.C (capital letter) on a Windows machine? or using a non-standard extension?

I've seen this happen when using Samba to Lint a Unix C++ program on a Windows PC Lint installation. If this is still an issue, look at the output lines indicating the module names like --- Module: ..., and look at the file type between parentheses. If switched off, you may need to use -vm (default).

If this is the case, I would expect many more warnings around the call, but interpreting the template <...> as two comparison operators would legitimately provoke this warning.

Other than that, the line you presented - without context - does not give any reason why 503 could be applicable here.

like image 168
Johan Bezem Avatar answered Jan 18 '23 19:01

Johan Bezem