diff --git a/system/lib/libcxxabi/src/cxa_noexception.cpp b/system/lib/libcxxabi/src/cxa_noexception.cpp index 47c0db67c0fe9..b70468347045e 100644 --- a/system/lib/libcxxabi/src/cxa_noexception.cpp +++ b/system/lib/libcxxabi/src/cxa_noexception.cpp @@ -74,6 +74,14 @@ void __cxa_free_exception(void *thrown_object) throw() { ((char *)cxa_exception_from_thrown_object(thrown_object)); free((void *)raw_buffer); } + +__cxa_exception* +__cxa_init_primary_exception(void* object, + std::type_info* tinfo, + void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() { + __cxa_exception* exception_header = cxa_exception_from_thrown_object(object); + return exception_header; +} #endif } // extern "C" diff --git a/test/test_other.py b/test/test_other.py index a967647eba253..937f99d561afd 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -14891,3 +14891,23 @@ def test_mimalloc_headers(self): def test_SUPPORT_BIG_ENDIAN(self): # Just a simple build-only test for now self.run_process([EMCC, '-sSUPPORT_BIG_ENDIAN', test_file('hello_world.c')]) + + @parameterized({ + 'noexcept': ['-fno-exceptions'], + 'default': [], + 'except': ['-sDISABLE_EXCEPTION_CATCHING=0'], + 'except_wasm': ['-fwasm-exceptions'], + 'except_wasm_exnref': ['-fwasm-exceptions', '-sWASM_EXNREF'] + }) + def test_std_promise_link(self, *args): + # Regression test for a bug where std::promise's destructor caused a link + # error with __cxa_init_primary_exception when no exception argument was + # given (which defaults to -fignore-exceptions) + create_file('src.cpp', r''' + #include + int main() { + std::promise p; + return 0; + } + ''') + self.run_process([EMXX, 'src.cpp', '-pthread'] + list(args))