Skip to content

Call of overloaded attachInterrupt is ambiguous with a lambda callback #1601

Closed
@NepEgor

Description

@NepEgor

When calling attachInterrupt with a lambda callback instead of a function I got the following error:

error: call of overloaded 'attachInterrupt(const uint8_t&, setup()::<lambda()>, int)' is ambiguous
   32 |     attachInterrupt(pin_trackpad_clock[0], [](){trackpad[0].int_on_clock();}, FALLING);
...
C:\Users\<user>\.platformio\packages\framework-arduinoststm32\cores\arduino/WInterrupts.h:28:8: note: candidate: 'void attachInterrupt(uint32_t, callback_function_t, uint32_t)'
   28 |   void attachInterrupt(uint32_t pin, callback_function_t callback, uint32_t mode);
      |        ^~~~~~~~~~~~~~~
C:\Users\<user>\.platformio\packages\framework-arduinoststm32\cores\arduino/WInterrupts.h:32:6: note: candidate: 'void attachInterrupt(uint32_t, void (*)(), uint32_t)'
   32 | void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode);
      |      ^~~~~~~~~~~~~~~

Header file WInterrupts.h indeed has 2 prototypes of this function and compiler can't decide which one to use with a lambda.
When the prototype with a function pointer (line 32) is removed, project compiles and works no matter attachInterrupt is called with a lambda or a function pointer.

Please note that Arduino version of attachInterrupt only has one prototype with a function pointer
and esp32 version has one prototype with std::function<void(void)>.

(Edit)
I am using default installation of PlatformIO in VS Code.
I have also tried the same concept with MSVC and MinGW with the same outcome.

Metadata

Metadata

Assignees

Labels

bug 🐛Something isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions