cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

I don't think cppcheck should warn if it can't find the standard header files

Open omarandlorraine opened this issue 3 years ago • 3 comments

I've just adjusted lib/preprocessor.cpp so that it will not warn anyone it can't find the header files.

My idea here is that if this

Please note: Cppcheck does not need standard library headers to get proper results.

is true, then the user shouldn't have to worry about whether the headers not found are ones Cppcheck also doesn't need.

Is this kind of thing good? In that case, it's trivial to add more filenames to ignore for this specific case.

omarandlorraine avatar Feb 11 '22 14:02 omarandlorraine

Gah! I realize now the branch is marred by the inclusion of commits from my other PR. Let me know if there's a problem here and I'll try to right it.

omarandlorraine avatar Feb 11 '22 14:02 omarandlorraine

This could actually be useful to detect missing custom/user-generated header files, which might be required for proper analysis (cf. various daca@home errors). Of course, your list is very much incomplete...

chrchr-github avatar Feb 18 '22 21:02 chrchr-github

I am not sure. I do develop Cppcheck for the use case that the stdio etc are not included. I never include system headers when I run Cppcheck myself. But technically it is possible to include the system headers and run cppcheck with that. Unfortunately I can image some bugs that can only be detected if the system headers are included. For instance if you use a standard struct that is not defined in std.cfg and have uninitialized member usage.

We could clarify the information message and say something like "we recommend that you use --library=std instead of including stdio.h" maybe?

And yes as @chrchr-github says the list of headers will definitely be incomplete always.

danmar avatar Feb 19 '22 09:02 danmar

You can suppress the warnings about system headers with --suppress=missingIncludeSystem.

I also think we should split the --enable= option missingInclude into a local and system version (I though I had a ticket field about this).

There's also an idea to move the library detection used in daca into the application so you don't have to manually specify --library. And there would be a different warning which would actually tell you about system headers which are not represented - see https://trac.cppcheck.net/ticket/11287 for much more detail.

I see no upside in the suggested change and think the proposed improvements might cover the intention of this change. So this PR should be closed.

firewave avatar Jan 21 '23 15:01 firewave

I close this. I think the interface can be discussed though .. if you have a sourceforge account feel free to open a discussion thread there..

danmar avatar Jan 26 '23 21:01 danmar