Wrong issues from cppcheck

Hi!
I am using platformio for a big project and i am checking it since a long time with cppcheck.
Since some days ago cppcheck is giving me wrong results (always a lot of errors of the unusedFunction kind).

example issue: https://github.com/lora-aprs/LoRa_APRS_iGate/runs/1671121401?check_suite_focus=true
this was the commit to the run: GitHub - lora-aprs/LoRa_APRS_iGate at 29972a00a0b82c2fbd8650656016be136cec9814
ini file: LoRa_APRS_iGate/platformio.ini at 29972a00a0b82c2fbd8650656016be136cec9814 · lora-aprs/LoRa_APRS_iGate · GitHub
and command which is running on github actions for cppcheck: platformio check --fail-on-defect low --fail-on-defect medium --fail-on-defect high --skip-packages --flags "--suppress=*:*.pio\* --inline-suppr" -v

do you have any input on this? or is this a bug from platformio?

Interesting:

When I reduce the LoRa_APRS_iGate.cpp to

#include <map>
#include <Arduino.h>
#include "display.h"
#include "configuration.h"

// cppcheck-suppress unusedFunction
void setup()
{
	setup_display();
	show_display("ABC");
	turn_off_display();
}

// cppcheck-suppress unusedFunction
void loop()
{
}

then

>pio check -e heltec_wifi_lora_32_v1 -v --skip-packages

src\display.cpp:12: [low:style] The function 'setup_display' is never used. [unusedFunction]
src\display.cpp:35: [low:style] The function 'show_display' is never used. [unusedFunction]
src\display.cpp:30: [low:style] The function 'turn_off_display' is never used. [unusedFunction]

when I remove #include "configuration.h"

>pio check -e heltec_wifi_lora_32_v1 -v --skip-packages
No defects found

So why is that? :smiley:

Aha. ArduinoJSON seems to be acting up.

#include <map>
#include <Arduino.h>
#include "display.h"
//#include <ArduinoJson.h>

// cppcheck-suppress unusedFunction
void setup()
{
	setup_display();
	show_display("ABC");
	turn_off_display();
}

// cppcheck-suppress unusedFunction
void loop()
{
}

results in 0 defects.

Uncommenting just the #include <ArduinoJson.h> line will make it spew defects again.

Edit:

Making PIO use an older version with

   bblanchon/ArduinoJson @ 6.9.1

with the code above (plus uncommented ArduinoJSON.h) results in a different error

src\configuration.cpp:20: [low:style] The function 'readConfiguration' is never used. [unusedFunction]
=

Edit 2:

Intersting, the Arduino JSON lib has a header called Configuration.hpp.

I’ve opened issue Inclusion of ArduinoJSON causes cppcheck to not recognize a call to a function · Issue #3797 · platformio/platformio-core · GitHub so that @ivankravets can have a look at that. No idea what’s causing it.

EDIT: Per posts below, the new cppcheck version reports an error, while the other one does not.

With that code, none should report an actual error. This will be further discussed in the issue.

1 Like

May also have something to do with cppcheck 2.3 being released 4 days ago… Releases · danmar/cppcheck · GitHub

thanks for testing so much around!
do you know how i can use an earlier version of cppcheck to test this?
i think for the meantime i will use a define to not include the json-lib for cppcheck :wink:

Going through the entire 3 available versions of tool-cppcheck availlable at the bintray by doing a platform_packages = tool-cppcheck@version in the platformio.ini hasn’t made a difference (or wasn’t used properly :confused:)

AAhhhh. You’re actually right.

Doing

…doesn’t actually change it. That’ll be another bug report at Changing tool-cppcheck version via platform_packages is ignored · Issue #3798 · platformio/platformio-core · GitHub.

The previous version does not report an failure. I’ve checked this by copying the 2.1.0 files into my folder C:\Users\<user>\.platformio\packages\tool-cppcheck directly, but not overwriting the package.json and .piopm file, and now it’s at

2/2 files checked 100% done


No defects found

so this really has also something to do with the cppcheck version 2.3.0 released 5 days ago or so.

thanks for taking a look into it! looks like the only approach is with a define now. :wink:

1 Like