5

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.

cafce25
  • 15,907
  • 4
  • 25
  • 31
SvenS
  • 795
  • 7
  • 15
  • 1
    In this particular case it should be possible to drop the `` altogether and just rely on type inference. (Not that this answers the question ;|) – Mankarse Sep 20 '11 at 12:20
  • @Mank: I saw it done like this in some tutorial. Didn't know if this was syntactically correct so I didn't mention it, but I already tried and encountered an error: `error C2784: 'void CViewAreaOleCtl::ShowWindowEx(HWND,int,ITypeToUse *)' : could not deduce template argument for 'ITypeToUse *' from 'ATL::CComPtr'` – SvenS Sep 20 '11 at 12:43
  • Did I mention `IActualType` is a COM interface? (Is it even of interest?) The class containing the two members is derived from COM classes as well. – SvenS Sep 20 '11 at 12:44
  • 1
    @SvenS: The problem is that you're taking a raw pointer, when really, you should be taking a plain type T. Then T can be deduced to be `ATL::CComPtr`. – Puppy Sep 21 '11 at 12:09
  • @DeadMG: You're right, that should be a valid work-around. I'll try it and append it as such to my question (it doesn't really solve the problem though). – SvenS Sep 21 '11 at 13:52
  • Have you tried reporting this directly to Gimpel? In my experience they're very responsive to problem reports - particularly if you supply a minimal example demonstrating the problem. – Alan Stokes Nov 28 '11 at 22:07
  • Yeah, I have. But I fell back on what @DeadMG suggested earlier. – SvenS Nov 29 '11 at 16:07

2 Answers2

1

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.

Johan Bezem
  • 2,582
  • 1
  • 20
  • 47
  • Sounds very plausible, I remember seeing some files written in all capitals occasionally, including the extension. I'm working on other issues by now, but I'll forward this to my colleague who took over this topic. – SvenS Nov 29 '12 at 12:42
0

Perhaps the reason is that there is already a definition of ShowWindowEx (one that is no template definition) in the Windows headers. Perhaps you should try to rename your function.

David Feurle
  • 2,687
  • 22
  • 38