Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cppcheck warns about unused functions (which are used!) #22

Open
pisanuw opened this issue Jan 16, 2019 · 7 comments
Open

cppcheck warns about unused functions (which are used!) #22

pisanuw opened this issue Jan 16, 2019 · 7 comments
Assignees

Comments

@pisanuw
Copy link

pisanuw commented Jan 16, 2019

Environment

  • Operating System (e.g. Ubuntu 16.04 x64): Darwin MAC-30223656 16.7.0 Darwin Kernel Version 16.7.0
  • IDE Version (e.g. CLion 2016.3.2): CLion 2018.2.3
  • Cppcheck executable version (cppcheck --version): Cppcheck 1.86
  • Cppcheck plugin version: 1.2.0
  • Exact strings used in cppcheck plugin options: --enable=all --force --inconclusive --language=c++ --std=c++14 --suppress=missingIncludeSystem
    • cppcheck path: /Users/pisan/xxx/bin/cppcheck
    • cppcheck options: ?

Expected behaviour

Do not warn about functions that are called

On command line
cppcheck --enable=all --force --inconclusive --language=c++ --std=c++14 --suppress=missingIncludeSystem *.cpp does not give any warnings

Actual behaviour

cppcheck: (style) The function funcFoo is never used warning in CLion right gutter as well as "Code Inspection"

Steps to reproduce the behaviour

main.cpp

#include <iostream>

void funcFoo();

int main() {
  funcFoo();
  return 0;
}

foo.cpp

void funcFoo() {

}
@firewave
Copy link
Collaborator

I also came across this. The command-line will not report the warning since it will scan all files in a single scan and see the usage. In the IDE it will only scan the separate file so it appear unused to it. I think it should use --suppress=unusedFunction for now to avoid this warnings.

I will also take a look at figuring out if this warning could be made a bit smarter - some ideas:

  • do not report as unused if only a single file is scanned and it is specified in the header
  • if a single file is used only report unused static functions
  • do not report unused functions at all when scanning a header

@firewave
Copy link
Collaborator

I created a ticket with Cppcheck - see https://trac.cppcheck.net/ticket/9682

@firewave
Copy link
Collaborator

firewave commented Nov 1, 2020

There's a similar issue with unusedStructMember warnings in headers - see https://trac.cppcheck.net/ticket/9961

@johnthagen
Copy link
Owner

johnthagen commented Nov 1, 2020

Yes, this is why --enable=unusedFunction is not enabled by default in the plugin. Based on how this plugin runs (one file at a time), these warnings are not displayed correctly in the IDE.

This is causes by the --enable=all flag in your configuration.

@firewave
Copy link
Collaborator

firewave commented Nov 1, 2020

Still Cppcheck could be smarter about this. Tickets are filed and hopefully at some point someone will care about it... (possibly me at some point :D)

@firewave
Copy link
Collaborator

Until Cppcheck behaves better I would suggest to internally disable these warnings for headers. I already have a patch ready.

@firewave firewave self-assigned this Nov 21, 2020
firewave added a commit to firewave/clion-cppcheck that referenced this issue Nov 21, 2020
firewave added a commit to firewave/clion-cppcheck that referenced this issue Dec 25, 2020
…s for header files to avoid false positives - fixes johnthagen#22
@firewave
Copy link
Collaborator

firewave commented Jan 14, 2022

I filed another ticket with an idea on how to improve this - see https://trac.cppcheck.net/ticket/10727.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants