Skip to content

Compiler warns about missing val::promise_type::unhandled_exception with -fno-exceptions #26289

@stevenwdv

Description

@stevenwdv

Given:

coro.cpp:

#include <emscripten/bind.h>
#include <emscripten/val.h>

static emscripten::val myCoro() { co_return 42; }

EMSCRIPTEN_BINDINGS(myBindings) {
  emscripten::function("myCoro", myCoro);
}

Compiling with -fno-exceptions, meaning __cpp_exceptions is not defined:

em++ -v -std=c++20 -lembind -fno-exceptions ./coro.cpp -o./coro.js
 "/home/swdv/emsdk/upstream/bin/clang++" -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=/home/swdv/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v -std=c++20 -fno-exceptions -c ./coro.cpp -o /tmp/emscripten_temp_sg7wryg7/coro.o
clang version 23.0.0git (https:/github.com/llvm/llvm-project 15cf81b13fd50e17092220f4730cb256a9a0da27)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/swdv/emsdk/upstream/bin
Build config: +assertions
 (in-process)
 "/home/swdv/emsdk/upstream/bin/clang-23" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -main-file-name coro.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility=hidden -debugger-tuning=gdb -fdebug-compilation-dir=/home/swdv/webtest -v -fcoverage-compilation-dir=/home/swdv/webtest -resource-dir /home/swdv/emsdk/upstream/lib/clang/23 -D EMSCRIPTEN -isysroot /home/swdv/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /home/swdv/emsdk/upstream/lib/clang/23/include -internal-isystem /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include -std=c++20 -fdeprecated-macro -ferror-limit 19 -fmessage-length=336 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fignore-exceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /tmp/emscripten_temp_sg7wryg7/coro.o -x c++ ./coro.cpp
clang -cc1 version 23.0.0git based upon LLVM 23.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "/home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
 /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/compat
 /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1
 /home/swdv/emsdk/upstream/lib/clang/23/include
 /home/swdv/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
./coro.cpp:4:24: warning: 'promise_type' is required to declare the member 'unhandled_exception()' when exceptions are enabled [-Wcoroutine-missing-unhandled-exception]
    4 | static emscripten::val myCoro() { co_return 42; }
      |                        ^
/home/swdv/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/val.h:725:12: note: 'promise_type' defined here                                                                                                                                                                                                                           
  725 | class val::promise_type {
      |            ^
1 warning generated.                                                                                                                                                                                                                                                                                                                            
 /home/swdv/emsdk/upstream/bin/clang --version
 /home/swdv/emsdk/node/22.16.0_64bit/bin/node /home/swdv/emsdk/upstream/emscripten/tools/compiler.mjs - --symbols-only
 /home/swdv/emsdk/upstream/bin/wasm-ld -o ./coro.wasm /tmp/tmp3c8hmsowlibemscripten_js_symbols.so --strip-debug --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=_emscripten_stack_alloc --export=__getTypeName --export=__wasm_call_ctors --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --stack-first --table-base=1 -lembind-rtti /tmp/emscripten_temp_sg7wryg7/coro.o -L/home/swdv/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -L/home/swdv/emsdk/upstream/emscripten/src/lib -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc-debug -lcompiler_rt -lc++-debug-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr
 /home/swdv/emsdk/upstream/bin/llvm-objcopy ./coro.wasm ./coro.wasm '--remove-section=llvm.func_attr.annotate.*' --remove-section=producers --remove-section=name '--remove-section=.debug*'
 /home/swdv/emsdk/node/22.16.0_64bit/bin/node /home/swdv/emsdk/upstream/emscripten/tools/compiler.mjs -

Note the -Wcoroutine-missing-unhandled-exception warning, which warns that if exceptions were enabled (which they are not), then you'd need to implement unhandled_exception (which is conditionally undefined here).

Consider silencing this or implementing unhandled_exception to just call std::terminate. Also feel free to close this issue if you think users should just add -Wno-coroutine-missing-unhandled-exception.

Version

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 5.0.2-git (8551146)
clang version 23.0.0git (llvm/llvm-project@15cf81b)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions