WIP: Add Analyzer Tool "Cppcheck (for C)"
AbandonedPublic

Authored by cullmann on Dec 8 2018, 4:02 PM.

Details

Reviewers
gregormi
Group Reviewers
Kate
Summary

I tried to run the current Cppcheck tool also on header files which
resulted in some errors because Cppcheck thought it was a C file.

In the new version of the Cppcheck tool "Cppcheck (C++ only)" the
parameter --language=c++ is set explicitly and header files are included
in the file filter.

With this setting more results were generated, e.g. in katemainwindow.h
several methods were marked as "not used", e.g. closeSplitView, which I
removed with this commit. The code still compiles fine though I am not
sure if the function is maybe supposed to be used from some external
project.

I find the following strange: if Cppcheck is only run on cpp files, it
still reports some issues in header files. But not as much as when I
explicitly feed it with the header files.

Diff Detail

Repository
R40 Kate
Branch
my_cppcheck2
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 5820
Build 5838: arc lint + arc unit
gregormi created this revision.Dec 8 2018, 4:02 PM
Restricted Application added a project: Kate. · View Herald TranscriptDec 8 2018, 4:02 PM
Restricted Application added a subscriber: kwrite-devel. · View Herald Transcript
gregormi requested review of this revision.Dec 8 2018, 4:02 PM
gregormi retitled this revision from Add Analyzser Tool "Cppcheck (C++ only)" to WIP: Add Analyzser Tool "Cppcheck (C++ only)".Dec 8 2018, 4:03 PM
gregormi edited the summary of this revision. (Show Details)
gregormi retitled this revision from WIP: Add Analyzser Tool "Cppcheck (C++ only)" to WIP: Add Analyzer Tool "Cppcheck (C++ only)".
gregormi edited the summary of this revision. (Show Details)
gregormi added a reviewer: Kate.
cullmann requested changes to this revision.Dec 8 2018, 5:15 PM
cullmann added a subscriber: cullmann.

Ähm :P closeSplitView is an API function exposed via the KTextEditor::MainWindow.
cppcheck can't see that, as called via invoke.
For the other thing: I have no issues with the second checker, but could the name be something better than "2"? :=)

This revision now requires changes to proceed.Dec 8 2018, 5:15 PM

Ähm :P closeSplitView is an API function exposed via the KTextEditor::MainWindow.
cppcheck can't see that, as called via invoke.

Does this explain why this issue is not reported by Cppcheck when the header files are not passed directly (when the first variant of Cppcheck is used)?

For the other thing: I have no issues with the second checker, but could the name be something better than "2"? :=)

Yes, I will rename it.

No idea ;=)
A static checker should not be able to detect that this method is unused (beside if it assumes its non-exported and it sees no calls in the complete program, but cppcheck normally doesn't analyze whole-program things).

Hmm. Now, I am in doubt if calling Cppcheck on header files directly is such a good idea after all.

;=)

If cppcheck works at least a bit like other checkers (like the one I work on, too: https://www.absint.com/rulechecker/ ), it should work on header files, too, and not only on compilation units.

The question is, how conservative some checks are, e.g. this "unused" seems a bit adventurous to assume a public method is unused.

sars added a subscriber: sars.Dec 8 2018, 9:16 PM

Wouldn't it be better to make it possible to configure the current CppCheck in stead of adding a new one?

At work I have a QML application with a bunch of models that expose functions to QML, but cppcheck does not know about that and warns about unused functions. I figure there could be more situations that the current cppcheck parameters are not optimal for...

I can imagine to have a second combobox which is defined per tool. It would contain commonly used options.
For the "Cppcheck (C++ only)" mode, the option would have to define arguments to the tool and make changes to the default file filter.

@Kåre, for your QML use case, could you define options in a similar way or what kind of flexibility would you need?

I dislike the fact that we have two times almost the same thing. Then again I can see that if C++ is set explicitly, the cppcheck plugin will be unusable for C. Then again, cppcheck contains 'cpp' in its name. So should we care about C at all here? If the answer is 'no', I would prefer to simply add the command line option and be done with it :-) or add an option in the Projects config page.

PS: i wrote this yesterday but forgot to click submit :p

addons/project/tools/kateprojectcodeanalysistoolcppcheck2.h
33–41

Unrelated to this patch:

  • All getters should be const in the base class, right?
  • virtual is not needed, since override already implies virtual.
kate/katemainwindow.h
373

If I am not mistaken: This should not be removed, since it's possibly called via the KTextEditor interface: https://github.com/KDE/ktexteditor/blob/master/src/utils/mainwindow.cpp#L152

Note this is a public Q_SLOT, meaning we can invoke this function via a QString trick we use to avoid binary compatibility issues... (not nice, but works!).

I dislike the fact that we have two times almost the same thing. Then again I can see that if C++ is set explicitly, the cppcheck plugin will be unusable for C. Then again, cppcheck contains 'cpp' in its name. So should we care about C at all here? If the answer is 'no', I would prefer to simply add the command line option and be done with it :-) or add an option in the Projects config page.

I like the idea:

  1. Restrict the original "Cppcheck (C++)" to C++ and remove the ".c" file extension from the list (and still do not search header files since these seem to generate false positives)
  2. Add another version "Cppcheck (C)" which is set to "c" and then only search within .c files.
addons/project/tools/kateprojectcodeanalysistoolcppcheck2.h
33–41

about const: yes, after rebase these will be const

kate/katemainwindow.h
373

Ah, good to know. I found this occurrence:

frameworks/ktexteditor/src/utils/mainwindow.cpp
146:bool MainWindow::closeSplitView(KTextEditor::View *view)
153: , "closeSplitView"

Christoph also mentioned it. I will revert this change.

gregormi retitled this revision from WIP: Add Analyzer Tool "Cppcheck (C++ only)" to WIP: Add Analyzer Tool "Cppcheck (C only)".Dec 9 2018, 9:35 AM
gregormi retitled this revision from WIP: Add Analyzer Tool "Cppcheck (C only)" to WIP: Add Analyzer Tool "Cppcheck (for C)".

Hmm, actually, would it not be just nicer to enhance the one cppcheck analysis class to feed the different language files with the correct parameters to cppcheck?
That way, we just can have one analyzer object dealing with cppcheck.

cullmann commandeered this revision.Apr 13 2019, 5:11 PM
cullmann edited reviewers, added: gregormi; removed: cullmann.

Please submit a new request to make the existing analysis more clever for different languages.

cullmann abandoned this revision.Apr 13 2019, 5:11 PM

Makes sense.