emscripten-core / emscripten-core/emscripten

Issue with function pointers/lambdas for callbacks

Open
#17,204 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Please include the following in your bug report:

**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.13 (531257621816c200bc7c3be53129494afd029aec)

**Failing command line in full:**
```
#include
#include

void tick() {
std::cout << "Tick" << std::endl;
}

void callback(std::function func) {
func();
}

extern "C" int main(int argc, char ** argv) {
callback(tick);
callback([&]() { std::cout << "Tick" << std::endl; });
}
```

I've distilled my issue down to the code above. The issue stems from each of the callback calls in the main function. They're both marked with (intellisense) errors as follows:
```
In template: no matching 'operator new' function for non-allocating placement new expression; include
```
Including the "new" header as suggested has no impact, and I'm not using the placement new operator anywhere.

This simple version compiles and runs, but a more complex example fails with an exception:
```
Uncaught RuntimeError: Aborted(native code called abort())
at abort (quickvideo_em.js:1444:11)
at _abort (quickvideo_em.js:6300:7)
at std::__2::__throw_system_error(int, char const*) (quickvideo_em.wasm:0x2258e)
at Timer::start() (quickvideo_em.wasm:0x1637)
at main (quickvideo_em.wasm:0x1362)
at quickvideo_em.js:1488:22
at callMain (quickvideo_em.js:7450:15)
at doRun (quickvideo_em.js:7507:23)
at quickvideo_em.js:7518:7
```

Does anyone know what the issue might be here? Thanks for any assistance.

**Full link command and output with `-v` appended:**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.