-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.
Milestone
Description
When attempting to use a C++ library which exposes a C API, if the library throws an exception anywhere, even if the exception is caught in the C++ library code (i.e. it isn't thrown in the C API), the binary will terminate.
This applies both when building Zig source files that include a C header and when building C files directly via Zig (i.e. zig build-exe --c-source whatever.c).
For instance, given the following files:
// test.cpp
#include "test.h"
int etc() {
try {
throw 1;
} catch (int x) {
// No-op
}
return 0;
}// test.h
#ifdef __cplusplus
extern "C" {
#endif
int etc();
#ifdef __cplusplus
}
#endif// main.c
#include "test.h"
int main() {
int x = etc();
return x;
}After building the executable, the binary terminates due to a thrown exception:
$ zig build-exe --c-source main.c --library c --object /nix/store/vgn1sxcj5ma9m5bhjps1q9jx3q2ab27c-gcc-8.3.0/lib64/libstdc++.a --object test.o --name main
$ ./main
terminate called after throwing an instance of 'int'
terminate called recursively
Aborted (core dumped)This issue doesn't exist when building the C file with gcc or clang.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.