emscripten-core / emscripten-core/emscripten
static const& variable within function leads to exception on exit
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.10 (b7dc6e5747465580df5984e723b9d1f10d8e804b)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 8f7e57485ee73205e108d74abb5565d5c63beaca)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\devel\emsdk\upstream\bin
```
Compile the code below as follows:
`em++ main.cpp -sEXIT_RUNTIME=1 -o main.html`
```cpp
#include
#include
const std::string& f()
{
static const std::string& x = {};
return x;
}
int main()
{
std::cout << f() << '\n';
}
```
Running in browser results in the following error in console:
```
Uncaught RuntimeError: null function or function signature mismatch
at main.wasm:0xf65
at exitRuntime (main.js:1:3158)
at exitJS (main.js:1:57013)
at callMain (main.js:1:58576)
at doRun (main.js:1:58955)
at main.js:1:59092
```
Seems like for other targets this code compiles and runs fine, so it shouldn't actually be UB
Contributor guide
Assessment
This issue has not been assessed yet.