ArduinoCore-API icon indicating copy to clipboard operation
ArduinoCore-API copied to clipboard

Fix -Wshadow warning for Interrupt callbacks

Open earlephilhower opened this issue 5 months ago • 1 comments

Adding -Wshadow to builds identified a template for the Interrupt callback which used a local variable the same as the function parameter. Rename the local variable to not shadow the parameter and make GCC happier.

The GCC warning for -Wshadow is as follows:

In file included from /home/earle/Arduino/hardware/pico/rp2040/cores/rp2040/api/../../../ArduinoCore-API/api/ArduinoAPI.h:29,
                 from /home/earle/Arduino/hardware/pico/rp2040/cores/rp2040/api/ArduinoAPI.h:2,
                 from /home/earle/Arduino/hardware/pico/rp2040/cores/rp2040/Arduino.h:28,
                 from /tmp/arduino_build_576215/sketch/DataLoggerUSB.ino.cpp:1:
/home/earle/Arduino/hardware/pico/rp2040/cores/rp2040/api/../../../ArduinoCore-API/api/Interrupts.h: In lambda function:
/home/earle/Arduino/hardware/pico/rp2040/cores/rp2040/api/../../../ArduinoCore-API/api/Interrupts.h:50:7: warning: declaration of 'T param' shadows a parameter [-Wshadow]
   50 |     T param = *(T*)((struct __container__<T>*)a)->param;
      |       ^~~~~
/home/earle/Arduino/hardware/pico/rp2040/cores/rp2040/api/../../../ArduinoCore-API/api/Interrupts.h:40:125: note: shadowed declaration is here
   40 | template<typename T> void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam<T> userFunc, PinStatus mode, T& param) {
      |                                                                                                                          ~~~^~~~~

earlephilhower avatar Sep 19 '25 02:09 earlephilhower

Unit tests looks like it's failing in some other part of the CI infra not related to the 2-line patch here

 /home/runner/work/ArduinoCore-API/ArduinoCore-API/test/src/String/test_move.cpp: In function ‘void C_A_T_C_H_T_E_S_T_4()’:
  /home/runner/work/ArduinoCore-API/ArduinoCore-API/test/src/String/test_move.cpp:45:7: error: moving ‘a’ of type ‘arduino::String’ to itself [-Werror=self-move]
     45 |     a = std::move(a);
        |     ~~^~~~~~~~~~~~~~
  /home/runner/work/ArduinoCore-API/ArduinoCore-API/test/src/String/test_move.cpp:45:7: note: remove ‘std::move’ call

earlephilhower avatar Sep 19 '25 02:09 earlephilhower