Inspect > Defects, setup/loop never used?

I ran “Inspect” on my Arduino Nano with the “Blink” test code. I got two “Defects”. At first I thought there were some errors in the memory hardware but when I clicked the defects tab, those were:

  • The function ‘setup’ is never used.
  • The function ‘loop’ is never used.

This is funny because the two functions were clearly used. Is this a bug?

#include <Arduino.h>

void setup() {

  // put your setup code here, to run once:



void loop() {

  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

  delay(1000);                       // wait for a second

  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW




Seems like inspector doesn’t really see the cores/arduino/main.cpp file in which these functions are called. Also occurs for me from the commandline for the same code.

>pio check
Checking uno > cppcheck (platform: atmelavr; board: uno; framework: arduino)
src\main.cpp:11: [medium:warning] The function 'loop' is never used. [unusedFunction]
src\main.cpp:3: [low:style] The function 'setup' is never used. [unusedFunction]
========================================================================================== [PASSED] Took 2.61 seconds ==========================================================================================

Component     HIGH    MEDIUM    LOW
-----------  ------  --------  -----
src            0        1        1

Total          0        1        1

Environment    Tool      Status    Duration
-------------  --------  --------  ------------
uno            cppcheck  PASSED    00:00:02.607
=============== 1 succeeded in 00:00:02.607 ===============

Please file a bug in

1 Like

It’s a known issue that was discussed and documented when the Project Inspection feature was added. Is a limitation of the fact that cppcheck doesn’t scan framework files (nor would you want it to - as any ‘errors’ there are not related to your code), so can’t reconcile that the setup() and loop() functions are actually used. Documented workaround is to put in comments that tell cppcheck to not check them for usage…